|
7 | 7 | from ..core import HSAClass
|
8 | 8 |
|
9 | 9 |
|
| 10 | +pytestmark = pytest.mark.remote_data |
| 11 | + |
| 12 | + |
10 | 13 | PACS_ENDINGS = ["571.xml", "571.jpg", "214.fits.gz", "008.fits.gz",
|
11 | 14 | "674.fits.gz", "350.fits.gz", "README.pdf"]
|
12 | 15 | SPIRE_ENDINGS = ["898.xml", "898.jpg", "141.fits.gz", "045.fits.gz", "952.fits.gz",
|
13 | 16 | "974.fits.gz", "715.fits.gz", "547.fits.gz", "770.fits.gz",
|
14 | 17 | "856.fits.gz", "148.fits.gz", "025.fits.gz", "538.fits.gz",
|
15 | 18 | "070.fits.gz", "434.fits.gz", "637.fits.gz", "835.fits.gz",
|
16 |
| - "372.fits.gz","248.fits.gz", "README.pdf"] |
| 19 | + "372.fits.gz", "248.fits.gz", "README.pdf"] |
17 | 20 |
|
18 | 21 |
|
19 |
| -@pytest.mark.remote_data |
20 |
| -class TestHSARemote: |
| 22 | +@pytest.mark.parametrize( |
| 23 | + "method,kwargs,expected_filename,expected_endings", |
| 24 | + [("download_data", {}, "1342191813.tar", PACS_ENDINGS), |
| 25 | + ("download_data", {"filename": "output_file"}, "output_file.tar", PACS_ENDINGS), |
| 26 | + ("download_data", {"compress": "true"}, "1342191813.tgz", PACS_ENDINGS), |
| 27 | + ("download_data", {"observation_id": "1342191188", "instrument_name": "SPIRE", "product_level": "LEVEL2", }, |
| 28 | + "1342191188.tar", SPIRE_ENDINGS), |
| 29 | + ("get_observation", {}, "1342191813.tar", PACS_ENDINGS)]) |
| 30 | +def test_download_data_observation( |
| 31 | + method, kwargs, expected_filename, expected_endings, tmp_path |
| 32 | +): |
| 33 | + parameters = {"observation_id": "1342191813", |
| 34 | + 'instrument_name': "PACS", |
| 35 | + 'product_level': 'LEVEL3', |
| 36 | + 'cache': False, |
| 37 | + 'download_dir': tmp_path} |
| 38 | + parameters.update(kwargs) |
| 39 | + if method == "download_data": |
| 40 | + res = HSAClass().download_data(**parameters, retrieval_type="OBSERVATION") |
| 41 | + elif method == "get_observation": |
| 42 | + res = HSAClass().get_observation(**parameters) |
| 43 | + assert Path(res) == tmp_path / expected_filename |
| 44 | + assert Path(res).is_file() |
| 45 | + with tarfile.open(res) as tar: |
| 46 | + names = tar.getnames() |
| 47 | + assert len(names) == len(expected_endings) |
| 48 | + for name, ending in zip(names, expected_endings): |
| 49 | + assert name.endswith(ending) |
21 | 50 |
|
22 |
| - @pytest.mark.parametrize( |
23 |
| - "method,kwargs,expected_filename,expected_endings", |
24 |
| - [ |
25 |
| - ("download_data", {}, "1342191813.tar", PACS_ENDINGS), |
26 |
| - ("download_data", {"filename": "output_file"}, "output_file.tar", PACS_ENDINGS), |
27 |
| - ("download_data", {"compress": "true"}, "1342191813.tgz", PACS_ENDINGS), |
28 |
| - ( |
29 |
| - "download_data", |
30 |
| - { |
31 |
| - "observation_id": "1342191188", |
32 |
| - "instrument_name": "SPIRE", |
33 |
| - "product_level": "LEVEL2", |
34 |
| - }, |
35 |
| - "1342191188.tar", |
36 |
| - SPIRE_ENDINGS, |
37 |
| - ), |
38 |
| - ("get_observation", {}, "1342191813.tar", PACS_ENDINGS), |
39 |
| - ], |
40 |
| - ) |
41 |
| - def test_download_data_observation( |
42 |
| - self, method, kwargs, expected_filename, expected_endings, tmp_path |
43 |
| - ): |
44 |
| - parameters = {"observation_id": "1342191813", |
45 |
| - 'instrument_name': "PACS", |
46 |
| - 'product_level': 'LEVEL3', |
47 |
| - 'cache': False, |
48 |
| - 'download_dir': tmp_path} |
49 |
| - parameters.update(kwargs) |
50 |
| - if method == "download_data": |
51 |
| - res = HSAClass().download_data(**parameters, retrieval_type="OBSERVATION") |
52 |
| - elif method == "get_observation": |
53 |
| - res = HSAClass().get_observation(**parameters) |
54 |
| - assert Path(res) == tmp_path / expected_filename |
55 |
| - assert Path(res).is_file() |
56 |
| - with tarfile.open(res) as tar: |
57 |
| - names = tar.getnames() |
58 |
| - assert len(names) == len(expected_endings) |
59 |
| - for name, ending in zip(names, expected_endings): |
60 |
| - assert name.endswith(ending) |
61 | 51 |
|
62 |
| - @pytest.mark.parametrize( |
63 |
| - "method,kwargs,expected_filename", |
64 |
| - [ |
65 |
| - ("download_data", {}, "1342191813.jpg"), |
66 |
| - ("download_data", {"filename": "output_file"}, "output_file.jpg"), |
67 |
| - ("get_postcard", {}, "1342191813.jpg"), |
68 |
| - ], |
69 |
| - ) |
70 |
| - def test_download_data_postcard(self, method, kwargs, expected_filename, tmp_path): |
71 |
| - parameters = {"observation_id": "1342191813", |
72 |
| - 'instrument_name': "PACS", |
73 |
| - 'cache': False, |
74 |
| - 'download_dir': tmp_path} |
75 |
| - if method == "download_data": |
76 |
| - res = HSAClass().download_data(**parameters, **kwargs, retrieval_type="POSTCARD") |
77 |
| - elif method == "get_postcard": |
78 |
| - res = HSAClass().get_postcard(**parameters, **kwargs) |
79 |
| - assert Path(res) == tmp_path / expected_filename |
80 |
| - assert Path(res).is_file() |
| 52 | +@pytest.mark.parametrize( |
| 53 | + "method,kwargs,expected_filename", |
| 54 | + [("download_data", {}, "1342191813.jpg"), |
| 55 | + ("download_data", {"filename": "output_file"}, "output_file.jpg"), |
| 56 | + ("get_postcard", {}, "1342191813.jpg")]) |
| 57 | +def test_download_data_postcard(method, kwargs, expected_filename, tmp_path): |
| 58 | + parameters = {"observation_id": "1342191813", |
| 59 | + 'instrument_name': "PACS", |
| 60 | + 'cache': False, |
| 61 | + 'download_dir': tmp_path} |
| 62 | + if method == "download_data": |
| 63 | + res = HSAClass().download_data(**parameters, **kwargs, retrieval_type="POSTCARD") |
| 64 | + elif method == "get_postcard": |
| 65 | + res = HSAClass().get_postcard(**parameters, **kwargs) |
| 66 | + assert Path(res) == tmp_path / expected_filename |
| 67 | + assert Path(res).is_file() |
0 commit comments