Skip to content

Commit a85d9e4

Browse files
authored
Merge pull request #3541 from esdc-esac-esa-int/ESA_euclid-update_get_productinput
Updated get_product to accept file_name as a python list
2 parents a2a2d0a + b1cae75 commit a85d9e4

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ esa.euclid
2626
- Methods ``cone_search`` and ``cross_match_basic`` now define the parameters ``table_name`` and ``ra_column_name`` and
2727
``dec_column_name`` independently [#3496]
2828

29+
- Method ``get_product`` now supports the input file_name as a Python list (e.g. ["file1.fits", "file2.fits"]) while
30+
still accepting the original comma separated string format. [#3541]
31+
2932
vizier
3033
^^^^^^
3134

astroquery/esa/euclid/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,8 @@ def get_product(self, *, file_name=None, product_id=None, schema='sedm', output_
13161316
Parameters
13171317
----------
13181318
file_name : str, optional, default None
1319-
file name for the product. More than one can be specified between comma. Either file_name or product_id
1320-
is mandatory
1319+
file name for the product. Can be a single string, including multiple file names separated
1320+
by commas, or a list of file name strings. Either file_name or product_id is mandatory.
13211321
product_id : str, optional, default None
13221322
product id. More than one can be specified between comma. Either file_name or product_id is mandatory
13231323
schema : str, optional, default 'sedm'
@@ -1345,6 +1345,9 @@ def get_product(self, *, file_name=None, product_id=None, schema='sedm', output_
13451345
if file_name is None and product_id is None:
13461346
raise ValueError("'file_name' and 'product_id' are both None")
13471347

1348+
if isinstance(file_name, (list, tuple)):
1349+
file_name = ",".join(file_name)
1350+
13481351
params_dict = {'TAPCLIENT': 'ASTROQUERY', 'RELEASE': schema}
13491352

13501353
if file_name is not None:

astroquery/esa/euclid/tests/test_euclidtap.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,58 @@ def test_get_product():
839839
remove_temp_dir()
840840

841841

842+
@patch.object(TapPlus, 'load_data')
843+
def test_get_product_with_list_of_filenames(mock_load_data, tmp_path_factory):
844+
"""
845+
Test that get_product accepts a list for file_name and converts it into
846+
a comma-separated string, while ensuring a real output file exists so
847+
__extract_file doesn't fail.
848+
"""
849+
850+
# Set up the enviornment
851+
conn_handler = DummyConnHandler()
852+
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
853+
connhandler=conn_handler)
854+
855+
responseLaunchJob = DummyResponse(200)
856+
responseLaunchJob.set_data(method='POST', context=None, body='', headers=None)
857+
conn_handler.set_default_response(responseLaunchJob)
858+
859+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
860+
861+
# Mock: create the file
862+
def _fake_load_data(*args, **kwargs):
863+
output_file = kwargs.get("output_file")
864+
# Create a dummy fits and directory
865+
of = Path(output_file)
866+
of.parent.mkdir(parents=True, exist_ok=True)
867+
of.write_bytes(b"SIMPLE = T\nEND\n")
868+
return None
869+
870+
mock_load_data.side_effect = _fake_load_data
871+
872+
# Input a as file names list
873+
filenames = ["file1.fits", "file2.fits", "file3.fits", "file4.fits"]
874+
875+
# Force an output name with .fits so that the extractor treats it as 1 file
876+
out_dir = tmp_path_factory.mktemp("euclid_tmp")
877+
output_file = str(out_dir / "dummy.fits")
878+
879+
result = tap.get_product(file_name=filenames, output_file=output_file)
880+
881+
# Must return a list of files (at least the one we created)
882+
assert result is not None
883+
assert isinstance(result, list)
884+
assert len(result) >= 1
885+
assert result[0].endswith(".fits")
886+
887+
# Verify that FILE_NAME is correct
888+
kwargs = mock_load_data.call_args.kwargs
889+
params_dict = kwargs.get("params_dict")
890+
assert params_dict["FILE_NAME"] == "file1.fits,file2.fits,file3.fits,file4.fits"
891+
assert params_dict["RETRIEVAL_TYPE"] == "FILE"
892+
893+
842894
def test_get_product_exceptions():
843895
conn_handler = DummyConnHandler()
844896
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',

0 commit comments

Comments
 (0)