14
14
15
15
16
16
"""
17
+ import datetime
17
18
import os
18
19
import zipfile
19
20
from pathlib import Path
85
86
RADIUS = 1 * u .deg
86
87
SKYCOORD = SkyCoord (ra = 19 * u .deg , dec = 20 * u .deg , frame = "icrs" )
87
88
89
+ FAKE_TIME = datetime .datetime (2024 , 1 , 1 , 0 , 0 , 59 )
90
+
91
+
92
+ @pytest .fixture
93
+ def patch_datetime_now (monkeypatch ):
94
+ class mydatetime (datetime .datetime ):
95
+ @classmethod
96
+ def now (cls , tz = None ):
97
+ return FAKE_TIME
98
+
99
+ monkeypatch .setattr (datetime , 'datetime' , mydatetime )
100
+
101
+
102
+ def test_patch_datetime (patch_datetime_now ):
103
+ assert datetime .datetime .now () == FAKE_TIME
104
+
88
105
89
106
@pytest .fixture (scope = "module" )
90
107
def column_attrs ():
@@ -170,7 +187,10 @@ def mock_querier():
170
187
171
188
172
189
@pytest .fixture (scope = "function" )
173
- def mock_datalink_querier ():
190
+ def mock_datalink_querier (patch_datetime_now ):
191
+
192
+ assert datetime .datetime .now (datetime .timezone .utc ) == FAKE_TIME
193
+
174
194
conn_handler = DummyConnHandler ()
175
195
tapplus = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
176
196
@@ -781,9 +801,15 @@ def test_cone_search_and_changing_MAIN_GAIA_TABLE(mock_querier_async):
781
801
assert "name_from_class" in job .parameters ["query" ]
782
802
783
803
784
- @pytest .mark .parametrize ("overwrite_output_file" , [False , True ])
804
+ @pytest .mark .parametrize ("overwrite_output_file" , [True ])
785
805
def test_datalink_querier_load_data_vot_exception (mock_datalink_querier , overwrite_output_file ):
786
- file_final = os .path .join (os .getcwd (), 'datalink_output.zip' )
806
+ assert datetime .datetime .now (datetime .timezone .utc ) == FAKE_TIME
807
+
808
+ now = datetime .datetime .now (datetime .timezone .utc )
809
+ output_file = 'datalink_output_' + now .strftime ("%Y%m%dT%H%M%S" ) + '.zip'
810
+
811
+ file_final = Path (os .getcwd () + '/' + output_file )
812
+
787
813
Path (file_final ).touch ()
788
814
789
815
assert os .path .exists (file_final )
@@ -973,7 +999,10 @@ def test_datalink_querier_load_data_fits(mock_datalink_querier_fits):
973
999
974
1000
975
1001
def test_load_data_vot (monkeypatch , tmp_path , tmp_path_factory ):
976
- path = Path (os .getcwd () + '/' + 'datalink_output.zip' )
1002
+ now = datetime .datetime .now (datetime .timezone .utc )
1003
+ output_file = 'datalink_output_' + now .strftime ("%Y%m%dT%H%M%S" ) + '.zip'
1004
+
1005
+ path = Path (os .getcwd () + '/' + output_file )
977
1006
978
1007
with open (DL_PRODUCTS_VOT , 'rb' ) as file :
979
1008
zip_bytes = file .read ()
@@ -988,7 +1017,7 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
988
1017
"RETRIEVAL_TYPE" : "epoch_photometry" ,
989
1018
"DATA_STRUCTURE" : "INDIVIDUAL" ,
990
1019
"USE_ZIP_ALWAYS" : "true" }
991
- assert output_file == os . getcwd () + '/' + 'datalink_output.zip'
1020
+ assert str ( path ) == output_file
992
1021
assert verbose is True
993
1022
994
1023
monkeypatch .setattr (TapPlus , "load_data" , load_data_monkeypatched )
@@ -1007,7 +1036,10 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
1007
1036
1008
1037
@pytest .mark .skip (reason = "Thes fits files generate an error relatate to the unit 'log(cm.s**-2)" )
1009
1038
def test_load_data_fits (monkeypatch , tmp_path , tmp_path_factory ):
1010
- path = Path (os .getcwd () + '/' + 'datalink_output.zip' )
1039
+ now = datetime .datetime .now (datetime .timezone .utc )
1040
+ output_file = 'datalink_output_' + now .strftime ("%Y%m%dT%H%M%S" ) + '.zip'
1041
+
1042
+ path = Path (os .getcwd () + '/' + output_file )
1011
1043
1012
1044
with open (DL_PRODUCTS_FITS , 'rb' ) as file :
1013
1045
zip_bytes = file .read ()
@@ -1040,7 +1072,10 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
1040
1072
1041
1073
1042
1074
def test_load_data_csv (monkeypatch , tmp_path , tmp_path_factory ):
1043
- path = Path (os .getcwd () + '/' + 'datalink_output.zip' )
1075
+ now = datetime .datetime .now (datetime .timezone .utc )
1076
+ output_file = 'datalink_output_' + now .strftime ("%Y%m%dT%H%M%S" ) + '.zip'
1077
+
1078
+ path = Path (os .getcwd () + '/' + output_file )
1044
1079
1045
1080
with open (DL_PRODUCTS_CSV , 'rb' ) as file :
1046
1081
zip_bytes = file .read ()
@@ -1055,7 +1090,7 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
1055
1090
"RETRIEVAL_TYPE" : "epoch_photometry" ,
1056
1091
"DATA_STRUCTURE" : "INDIVIDUAL" ,
1057
1092
"USE_ZIP_ALWAYS" : "true" }
1058
- assert output_file == os . getcwd () + '/' + 'datalink_output.zip'
1093
+ assert str ( path ) == output_file
1059
1094
assert verbose is True
1060
1095
1061
1096
monkeypatch .setattr (TapPlus , "load_data" , load_data_monkeypatched )
@@ -1073,7 +1108,10 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
1073
1108
1074
1109
1075
1110
def test_load_data_ecsv (monkeypatch , tmp_path , tmp_path_factory ):
1076
- path = Path (os .getcwd () + '/' + 'datalink_output.zip' )
1111
+ now = datetime .datetime .now (datetime .timezone .utc )
1112
+ output_file = 'datalink_output_' + now .strftime ("%Y%m%dT%H%M%S" ) + '.zip'
1113
+
1114
+ path = Path (os .getcwd () + '/' + output_file )
1077
1115
1078
1116
with open (DL_PRODUCTS_ECSV , 'rb' ) as file :
1079
1117
zip_bytes = file .read ()
@@ -1088,7 +1126,7 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
1088
1126
"RETRIEVAL_TYPE" : "epoch_photometry" ,
1089
1127
"DATA_STRUCTURE" : "INDIVIDUAL" ,
1090
1128
"USE_ZIP_ALWAYS" : "true" }
1091
- assert output_file == os . getcwd () + '/' + 'datalink_output.zip'
1129
+ assert str ( path ) == output_file
1092
1130
assert verbose is True
1093
1131
1094
1132
monkeypatch .setattr (TapPlus , "load_data" , load_data_monkeypatched )
@@ -1106,7 +1144,10 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
1106
1144
1107
1145
1108
1146
def test_load_data_linking_parameter (monkeypatch , tmp_path ):
1109
- path = Path (os .getcwd () + '/' + 'datalink_output.zip' )
1147
+ now = datetime .datetime .now (datetime .timezone .utc )
1148
+ output_file = 'datalink_output_' + now .strftime ("%Y%m%dT%H%M%S" ) + '.zip'
1149
+
1150
+ path = Path (os .getcwd () + '/' + output_file )
1110
1151
1111
1152
with open (DL_PRODUCTS_VOT , 'rb' ) as file :
1112
1153
zip_bytes = file .read ()
@@ -1121,7 +1162,7 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
1121
1162
"RETRIEVAL_TYPE" : "epoch_photometry" ,
1122
1163
"DATA_STRUCTURE" : "INDIVIDUAL" ,
1123
1164
"USE_ZIP_ALWAYS" : "true" }
1124
- assert output_file == os . getcwd () + '/' + 'datalink_output.zip'
1165
+ assert str ( path ) == output_file
1125
1166
assert verbose is True
1126
1167
1127
1168
monkeypatch .setattr (TapPlus , "load_data" , load_data_monkeypatched )
@@ -1140,7 +1181,10 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
1140
1181
1141
1182
@pytest .mark .parametrize ("linking_param" , ['TRANSIT_ID' , 'IMAGE_ID' ])
1142
1183
def test_load_data_linking_parameter_with_values (monkeypatch , tmp_path , linking_param ):
1143
- path = Path (os .getcwd () + '/' + 'datalink_output.zip' )
1184
+ now = datetime .datetime .now (datetime .timezone .utc )
1185
+ output_file = 'datalink_output_' + now .strftime ("%Y%m%dT%H%M%S" ) + '.zip'
1186
+
1187
+ path = Path (os .getcwd () + '/' + output_file )
1144
1188
1145
1189
with open (DL_PRODUCTS_VOT , 'rb' ) as file :
1146
1190
zip_bytes = file .read ()
0 commit comments