|
1 |
| -import { calculatePaths } from '../../src/plugins/fetch'; |
| 1 | +import { calculateFetchPaths } from '../../src/plugins/calculateFetchPaths'; |
2 | 2 | import { FetchConfig } from '../../src/pyconfig';
|
3 | 3 |
|
4 | 4 | describe('CalculateFetchPaths', () => {
|
5 | 5 | it('should calculate paths when only from is provided', () => {
|
6 | 6 | const fetch_cfg: FetchConfig[] = [{ from: 'http://a.com/data.csv' }];
|
7 |
| - const [paths, fetchPaths] = calculatePaths(fetch_cfg); |
8 |
| - expect(paths).toStrictEqual(['./data.csv']); |
9 |
| - expect(fetchPaths).toStrictEqual(['http://a.com/data.csv']); |
| 7 | + const res = calculateFetchPaths(fetch_cfg); |
| 8 | + expect(res).toStrictEqual([{ url: 'http://a.com/data.csv', path: 'data.csv' }]); |
10 | 9 | });
|
11 | 10 |
|
12 | 11 | it('should calculate paths when only files is provided', () => {
|
13 |
| - const fetch_cfg: FetchConfig[] = [{ files: ['foo/__init__.py', 'foo/mod.py'] }]; |
14 |
| - const [paths, fetchPaths] = calculatePaths(fetch_cfg); |
15 |
| - expect(paths).toStrictEqual(['./foo/__init__.py', './foo/mod.py']); |
16 |
| - expect(fetchPaths).toStrictEqual(['foo/__init__.py', 'foo/mod.py']); |
| 12 | + const fetch_cfg: FetchConfig[] = [{ files: ['foo/__init__.py', 'foo/mod.py', 'foo2/mod.py'] }]; |
| 13 | + const res = calculateFetchPaths(fetch_cfg); |
| 14 | + expect(res).toStrictEqual([ |
| 15 | + { url: 'foo/__init__.py', path: 'foo/__init__.py' }, |
| 16 | + { url: 'foo/mod.py', path: 'foo/mod.py' }, |
| 17 | + { url: 'foo2/mod.py', path: 'foo2/mod.py' }, |
| 18 | + ]); |
17 | 19 | });
|
18 | 20 |
|
19 | 21 | it('should calculate paths when files and to_folder is provided', () => {
|
20 | 22 | const fetch_cfg: FetchConfig[] = [{ files: ['foo/__init__.py', 'foo/mod.py'], to_folder: '/my/lib/' }];
|
21 |
| - const [paths, fetchPaths] = calculatePaths(fetch_cfg); |
22 |
| - expect(paths).toStrictEqual(['/my/lib/foo/__init__.py', '/my/lib/foo/mod.py']); |
23 |
| - expect(fetchPaths).toStrictEqual(['foo/__init__.py', 'foo/mod.py']); |
| 23 | + const res = calculateFetchPaths(fetch_cfg); |
| 24 | + expect(res).toStrictEqual([ |
| 25 | + { url: 'foo/__init__.py', path: '/my/lib/foo/__init__.py' }, |
| 26 | + { url: 'foo/mod.py', path: '/my/lib/foo/mod.py' }, |
| 27 | + ]); |
24 | 28 | });
|
25 | 29 |
|
26 | 30 | it('should calculate paths when from and files and to_folder is provided', () => {
|
27 | 31 | const fetch_cfg: FetchConfig[] = [
|
28 | 32 | { from: 'http://a.com/download/', files: ['foo/__init__.py', 'foo/mod.py'], to_folder: '/my/lib/' },
|
29 | 33 | ];
|
30 |
| - const [paths, fetchPaths] = calculatePaths(fetch_cfg); |
31 |
| - expect(paths).toStrictEqual(['/my/lib/foo/__init__.py', '/my/lib/foo/mod.py']); |
32 |
| - expect(fetchPaths).toStrictEqual(['http://a.com/download/foo/__init__.py', 'http://a.com/download/foo/mod.py']); |
| 34 | + const res = calculateFetchPaths(fetch_cfg); |
| 35 | + expect(res).toStrictEqual([ |
| 36 | + { url: 'http://a.com/download/foo/__init__.py', path: '/my/lib/foo/__init__.py' }, |
| 37 | + { url: 'http://a.com/download/foo/mod.py', path: '/my/lib/foo/mod.py' }, |
| 38 | + ]); |
33 | 39 | });
|
34 | 40 |
|
35 | 41 | it("should error out while calculating paths when filename cannot be determined from 'from'", () => {
|
36 | 42 | const fetch_cfg: FetchConfig[] = [{ from: 'http://google.com/', to_folder: '/tmp' }];
|
37 |
| - expect(() => calculatePaths(fetch_cfg)).toThrowError( |
| 43 | + expect(() => calculateFetchPaths(fetch_cfg)).toThrowError( |
38 | 44 | "Couldn't determine the filename from the path http://google.com/",
|
39 | 45 | );
|
40 | 46 | });
|
41 | 47 |
|
42 | 48 | it('should calculate paths when to_file is explicitly supplied', () => {
|
43 | 49 | const fetch_cfg: FetchConfig[] = [{ from: 'http://a.com/data.csv?version=1', to_file: 'pkg/tmp/data.csv' }];
|
44 |
| - const [paths, fetchPaths] = calculatePaths(fetch_cfg); |
45 |
| - expect(paths).toStrictEqual(['./pkg/tmp/data.csv']); |
46 |
| - expect(fetchPaths).toStrictEqual(['http://a.com/data.csv?version=1']); |
| 50 | + const res = calculateFetchPaths(fetch_cfg); |
| 51 | + expect(res).toStrictEqual([{ path: 'pkg/tmp/data.csv', url: 'http://a.com/data.csv?version=1' }]); |
47 | 52 | });
|
48 | 53 |
|
49 | 54 | it('should error out when both to_file and files parameters are provided', () => {
|
50 | 55 | const fetch_cfg: FetchConfig[] = [
|
51 | 56 | { from: 'http://a.com/data.csv?version=1', to_file: 'pkg/tmp/data.csv', files: ['a.py', 'b.py'] },
|
52 | 57 | ];
|
53 |
| - expect(() => calculatePaths(fetch_cfg)).toThrowError("Cannot use 'to_file' and 'files' parameters together!"); |
| 58 | + expect(() => calculateFetchPaths(fetch_cfg)).toThrowError( |
| 59 | + "Cannot use 'to_file' and 'files' parameters together!", |
| 60 | + ); |
54 | 61 | });
|
55 | 62 | });
|
0 commit comments