Skip to content

Commit 154d5e7

Browse files
Jorge Fernandez HernandezJorge Fernandez Hernandez
authored andcommitted
GAIAMNGT-1700 The name of the output file contains the timestamp with the format "%Y%m%dT%H%M%S"
1 parent ea2c414 commit 154d5e7

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed

astroquery/gaia/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,15 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr
232232

233233
output_file_specified = False
234234

235+
now = datetime.now(timezone.utc)
235236
if not dump_to_file:
236-
now = datetime.now(timezone.utc)
237237
now_formatted = now.strftime("%Y%m%d_%H%M%S")
238238
temp_dirname = "temp_" + now_formatted
239239
downloadname_formated = "download_" + now_formatted
240240
output_file = os.path.join(os.getcwd(), temp_dirname, downloadname_formated)
241241

242242
else:
243-
output_file = 'datalink_output.zip'
243+
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
244244
output_file_specified = True
245245
output_file = os.path.abspath(output_file)
246246
log.info(f"DataLink products will be stored in the {output_file} file")

astroquery/gaia/tests/test_gaiatap.py

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ def test_datalink_querier_load_data_vot_exception(mock_datalink_querier, overwri
802802

803803
assert str(
804804
excinfo.value) == (
805-
f"{file_final} file already exists. Please use overwrite_output_file='True' to overwrite output file.")
805+
f"{file_final} file already exists. Please use overwrite_output_file='True' to overwrite output "
806+
f"file.")
806807

807808
else:
808809
mock_datalink_querier.load_data(ids=[5937083312263887616], data_release='Gaia DR3',
@@ -828,11 +829,18 @@ def test_datalink_querier_load_data_vot(mock_datalink_querier):
828829
format="votable", dump_to_file=True, overwrite_output_file=True,
829830
verbose=False)
830831

831-
assert os.path.exists(os.path.join(os.getcwd(), 'datalink_output.zip'))
832+
direc = os.getcwd()
833+
files = os.listdir(direc)
834+
# Filtering only the files.
835+
files = [f for f in files if
836+
os.path.isfile(direc + '/' + f) and f.endswith(".zip") and f.startswith('datalink_output')]
837+
838+
assert len(files) == 1
839+
datalink_output = files[0]
832840

833841
extracted_files = []
834842

835-
with zipfile.ZipFile('datalink_output.zip', "r") as zip_ref:
843+
with zipfile.ZipFile(datalink_output, "r") as zip_ref:
836844
extracted_files.extend(zip_ref.namelist())
837845

838846
assert len(extracted_files) == 3
@@ -845,9 +853,9 @@ def test_datalink_querier_load_data_vot(mock_datalink_querier):
845853
assert files[1] == 'XP_CONTINUOUS-Gaia DR3 5937083312263887616.xml'
846854
assert files[2] == 'XP_SAMPLED-Gaia DR3 5937083312263887616.xml'
847855

848-
os.remove(os.path.join(os.getcwd(), 'datalink_output.zip'))
856+
os.remove(os.path.join(os.getcwd(), datalink_output))
849857

850-
assert not os.path.exists(os.path.join(os.getcwd(), 'datalink_output.zip'))
858+
assert not os.path.exists(os.path.join(os.getcwd(), datalink_output))
851859

852860

853861
def test_datalink_querier_load_data_ecsv(mock_datalink_querier_ecsv):
@@ -859,11 +867,18 @@ def test_datalink_querier_load_data_ecsv(mock_datalink_querier_ecsv):
859867
format="ecsv", dump_to_file=True, overwrite_output_file=True,
860868
verbose=False)
861869

862-
assert os.path.exists('datalink_output.zip')
870+
direc = os.getcwd()
871+
files = os.listdir(direc)
872+
# Filtering only the files.
873+
files = [f for f in files if
874+
os.path.isfile(direc + '/' + f) and f.endswith(".zip") and f.startswith('datalink_output')]
875+
876+
assert len(files) == 1
877+
datalink_output = files[0]
863878

864879
extracted_files = []
865880

866-
with zipfile.ZipFile('datalink_output.zip', "r") as zip_ref:
881+
with zipfile.ZipFile(datalink_output, "r") as zip_ref:
867882
extracted_files.extend(zip_ref.namelist())
868883

869884
assert len(extracted_files) == 3
@@ -876,9 +891,9 @@ def test_datalink_querier_load_data_ecsv(mock_datalink_querier_ecsv):
876891
assert files[1] == 'XP_CONTINUOUS-Gaia DR3 5937083312263887616.ecsv'
877892
assert files[2] == 'XP_SAMPLED-Gaia DR3 5937083312263887616.ecsv'
878893

879-
os.remove(os.path.join(os.getcwd(), 'datalink_output.zip'))
894+
os.remove(os.path.join(os.getcwd(), datalink_output))
880895

881-
assert not os.path.exists('datalink_output.zip')
896+
assert not os.path.exists(datalink_output)
882897

883898

884899
def test_datalink_querier_load_data_csv(mock_datalink_querier_csv):
@@ -890,11 +905,18 @@ def test_datalink_querier_load_data_csv(mock_datalink_querier_csv):
890905
format="csv", dump_to_file=True, overwrite_output_file=True,
891906
verbose=False)
892907

893-
assert os.path.exists('datalink_output.zip')
908+
direc = os.getcwd()
909+
files = os.listdir(direc)
910+
# Filtering only the files.
911+
files = [f for f in files if
912+
os.path.isfile(direc + '/' + f) and f.endswith(".zip") and f.startswith('datalink_output')]
913+
914+
assert len(files) == 1
915+
datalink_output = files[0]
894916

895917
extracted_files = []
896918

897-
with zipfile.ZipFile('datalink_output.zip', "r") as zip_ref:
919+
with zipfile.ZipFile(datalink_output, "r") as zip_ref:
898920
extracted_files.extend(zip_ref.namelist())
899921

900922
assert len(extracted_files) == 3
@@ -907,9 +929,9 @@ def test_datalink_querier_load_data_csv(mock_datalink_querier_csv):
907929
assert files[1] == 'XP_CONTINUOUS-Gaia DR3 5937083312263887616.csv'
908930
assert files[2] == 'XP_SAMPLED-Gaia DR3 5937083312263887616.csv'
909931

910-
os.remove(os.path.join(os.getcwd(), 'datalink_output.zip'))
932+
os.remove(os.path.join(os.getcwd(), datalink_output))
911933

912-
assert not os.path.exists('datalink_output.zip')
934+
assert not os.path.exists(datalink_output)
913935

914936

915937
@pytest.mark.skip(reason="Thes fits files generate an error relatate to the unit 'log(cm.s**-2)")
@@ -922,11 +944,18 @@ def test_datalink_querier_load_data_fits(mock_datalink_querier_fits):
922944
format="fits", dump_to_file=True, overwrite_output_file=True,
923945
verbose=False)
924946

925-
assert os.path.exists('datalink_output.zip')
947+
direc = os.getcwd()
948+
files = os.listdir(direc)
949+
# Filtering only the files.
950+
files = [f for f in files if
951+
os.path.isfile(direc + '/' + f) and f.endswith(".zip") and f.startswith('datalink_output')]
952+
953+
assert len(files) == 1
954+
datalink_output = files[0]
926955

927956
extracted_files = []
928957

929-
with zipfile.ZipFile('datalink_output.zip', "r") as zip_ref:
958+
with zipfile.ZipFile(datalink_output, "r") as zip_ref:
930959
extracted_files.extend(zip_ref.namelist())
931960

932961
assert len(extracted_files) == 3
@@ -939,9 +968,9 @@ def test_datalink_querier_load_data_fits(mock_datalink_querier_fits):
939968
assert files[1] == 'XP_CONTINUOUS-Gaia DR3 5937083312263887616.fits'
940969
assert files[2] == 'XP_SAMPLED-Gaia DR3 5937083312263887616.fits'
941970

942-
os.remove(os.path.join(os.getcwd(), 'datalink_output.zip'))
971+
os.remove(os.path.join(os.getcwd(), datalink_output))
943972

944-
assert not os.path.exists('datalink_output.zip')
973+
assert not os.path.exists(datalink_output)
945974

946975

947976
def test_load_data_vot(monkeypatch, tmp_path, tmp_path_factory):

0 commit comments

Comments
 (0)