Skip to content

Commit 975affb

Browse files
Jorge Fernandez HernandezJorge Fernandez Hernandez
authored andcommitted
EUCLIDPCR-1863 new tests
1 parent 3fe1395 commit 975affb

File tree

2 files changed

+124
-2
lines changed

2 files changed

+124
-2
lines changed

astroquery/esa/euclid/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,12 +1117,12 @@ def get_cutout(self, *, file_path=None, instrument=None, id=None, coordinate, ra
11171117
self.__euclidcutout.load_data(params_dict=params_dict, output_file=output_file_full_path, verbose=verbose)
11181118
except HTTPError as err:
11191119
log.error(
1120-
f"Cannot retrieve the product for file_path %{file_path}, obsId {id}, and collection {instrument}. "
1120+
f"Cannot retrieve the product for file_path {file_path}, obsId {id}, and collection {instrument}. "
11211121
f"HTTP error: {err}")
11221122
return
11231123
except Exception as exx:
11241124
log.error(
1125-
f"Cannot retrieve the product for file_path %{file_path}, obsId {id}, and collection {instrument}: "
1125+
f"Cannot retrieve the product for file_path {file_path}, obsId {id}, and collection {instrument}: "
11261126
f"{str(exx)}")
11271127
return
11281128

astroquery/esa/euclid/tests/test_euclidtap.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,34 @@ def test_get_product_exceptions():
714714
assert str(exc_info.value).startswith("'file_name' and 'product_id' are both None")
715715

716716

717+
@patch.object(TapPlus, 'load_data')
718+
def test_get_product_exceptions_2(mock_load_data, caplog):
719+
conn_handler = DummyConnHandler()
720+
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
721+
connhandler=conn_handler)
722+
# Launch response: we use default response because the query contains decimals
723+
responseLaunchJob = DummyResponse(200)
724+
responseLaunchJob.set_data(method='POST', context=None, body='', headers=None)
725+
726+
conn_handler.set_default_response(responseLaunchJob)
727+
728+
mock_load_data.side_effect = HTTPError("launch_job_async HTTPError")
729+
730+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
731+
732+
tap.get_product(file_name='hola.fits', output_file=None)
733+
734+
mssg = "Cannot retrieve products for file_name hola.fits or product_id None. HTTP error: launch_job_async HTTPError"
735+
assert caplog.records[0].msg == mssg
736+
737+
mock_load_data.side_effect = Exception("launch_job_async Exception")
738+
739+
tap.get_product(file_name='hola.fits', output_file=None)
740+
741+
mssg = "Cannot retrieve products for file_name hola.fits or product_id None: launch_job_async Exception"
742+
assert caplog.records[1].msg == mssg
743+
744+
717745
def test_get_obs_products():
718746
conn_handler = DummyConnHandler()
719747
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
@@ -763,6 +791,34 @@ def test_get_obs_products_exceptions():
763791
assert str(exc_info.value).startswith("Invalid product type XXXXXXXX. Valid values: ['observation', 'mosaic']")
764792

765793

794+
@patch.object(TapPlus, 'load_data')
795+
def test_get_obs_products_exceptions_2(mock_load_data, caplog):
796+
conn_handler = DummyConnHandler()
797+
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
798+
connhandler=conn_handler)
799+
# Launch response: we use default response because the query contains decimals
800+
responseLaunchJob = DummyResponse(200)
801+
responseLaunchJob.set_data(method='POST', context=None, body='', headers=None)
802+
803+
conn_handler.set_default_response(responseLaunchJob)
804+
805+
mock_load_data.side_effect = HTTPError("launch_job_async HTTPError")
806+
807+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
808+
809+
tap.get_observation_products(id=12345, product_type='observation', filter='VIS', output_file=None)
810+
811+
mssg = "Cannot retrieve products for observation 12345. HTTP error: launch_job_async HTTPError"
812+
assert caplog.records[0].msg == mssg
813+
814+
mock_load_data.side_effect = Exception("launch_job_async Exception")
815+
816+
tap.get_observation_products(id=12345, product_type='observation', filter='VIS', output_file=None)
817+
818+
mssg = "Cannot retrieve products for observation 12345: launch_job_async Exception"
819+
assert caplog.records[1].msg == mssg
820+
821+
766822
def test_get_cutout():
767823
conn_handler = DummyConnHandler()
768824
tap_plus = TapPlus(url="http://test:1111/tap", data_context='cutout', client_id='ASTROQUERY',
@@ -843,6 +899,43 @@ def test_get_cutout_exception():
843899
assert str(exc_info.value).startswith('Missing required argument')
844900

845901

902+
@patch.object(TapPlus, 'load_data')
903+
def test_get_cutout_exceptions_2(mock_load_data, caplog):
904+
conn_handler = DummyConnHandler()
905+
tap_plus = TapPlus(url="http://test:1111/tap", data_context='cutout', client_id='ASTROQUERY',
906+
connhandler=conn_handler)
907+
908+
cutout_handler = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
909+
connhandler=conn_handler)
910+
# tap.set_cutout_context()
911+
# Launch response: we use default response because the query contains decimals
912+
responseLaunchJob = DummyResponse(200)
913+
responseLaunchJob.set_data(method='POST', context=None, body='', headers=None)
914+
915+
conn_handler.set_default_response(responseLaunchJob)
916+
917+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, cutout_handler=cutout_handler,
918+
show_server_messages=False)
919+
920+
mock_load_data.side_effect = HTTPError("launch_job_async HTTPError")
921+
922+
tap.get_cutout(file_path='hola.fits', instrument='NISP', id='19704', coordinate=SKYCOORD, radius=1 * u.arcmin,
923+
output_file=None)
924+
925+
mssg = ("Cannot retrieve the product for file_path hola.fits, obsId 19704, and collection NISP. HTTP error: "
926+
"launch_job_async HTTPError")
927+
assert caplog.records[0].msg == mssg
928+
929+
mock_load_data.side_effect = Exception("launch_job_async Exception")
930+
931+
tap.get_cutout(file_path='hola.fits', instrument='NISP', id='19704', coordinate=SKYCOORD, radius=1 * u.arcmin,
932+
output_file=None)
933+
934+
mssg = ("Cannot retrieve the product for file_path hola.fits, obsId 19704, and collection NISP: launch_job_async "
935+
"Exception")
936+
assert caplog.records[1].msg == mssg
937+
938+
846939
def test_get_spectrum():
847940
conn_handler = DummyConnHandler()
848941
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
@@ -862,6 +955,35 @@ def test_get_spectrum():
862955
remove_temp_dir()
863956

864957

958+
@patch.object(TapPlus, 'load_data')
959+
def test_get_spectrum_exceptions_2(mock_load_data, caplog):
960+
conn_handler = DummyConnHandler()
961+
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
962+
connhandler=conn_handler)
963+
# Launch response: we use default response because the query contains decimals
964+
responseLaunchJob = DummyResponse(200)
965+
responseLaunchJob.set_data(method='POST', context=None, body='', headers=None)
966+
967+
conn_handler.set_default_response(responseLaunchJob)
968+
969+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
970+
971+
mock_load_data.side_effect = HTTPError("launch_job_async HTTPError")
972+
973+
tap.get_spectrum(source_id='2417660845403252054', schema='sedm_sc8', output_file=None)
974+
975+
mssg = ("Cannot retrieve spectrum for source_id 2417660845403252054, schema sedm_sc8. HTTP error: launch_job_async "
976+
"HTTPError")
977+
assert caplog.records[0].msg == mssg
978+
979+
mock_load_data.side_effect = Exception("launch_job_async Exception")
980+
981+
tap.get_spectrum(source_id='2417660845403252054', schema='sedm_sc8', output_file=None)
982+
983+
mssg = "Cannot retrieve spectrum for source_id 2417660845403252054, schema sedm_sc8: launch_job_async Exception"
984+
assert caplog.records[1].msg == mssg
985+
986+
865987
def remove_temp_dir():
866988
dirs = glob.glob('./temp_*')
867989
for dir_path in dirs:

0 commit comments

Comments
 (0)