Skip to content

Commit 6d0c58e

Browse files
Jorge Fernandez HernandezJorge Fernandez Hernandez
authored andcommitted
EUCLIDPCR-1914 Update tests that catch very generic Exceptions. Also they match the error message without a new assert line.
1 parent f1b6158 commit 6d0c58e

File tree

1 file changed

+18
-51
lines changed

1 file changed

+18
-51
lines changed

astroquery/esa/euclid/tests/test_euclidtap.py

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -645,37 +645,25 @@ def test_get_product_list_by_tile_index():
645645
def test_get_product_list_errors():
646646
tap = EuclidClass()
647647

648-
with pytest.raises(ValueError) as exc_info:
648+
with pytest.raises(ValueError, match="Missing required argument: 'product_type'"):
649649
tap.get_product_list(observation_id='13', product_type=None)
650650

651-
assert str(exc_info.value).startswith("Missing required argument: 'product_type'")
652-
653-
with pytest.raises(ValueError) as exc_info:
651+
with pytest.raises(ValueError,
652+
match="Missing required argument: 'observation_id'; Missing required argument: 'tile_id'"):
654653
tap.get_product_list(observation_id=None, tile_index=None, product_type='DpdNirStackedFrame')
655654

656-
assert str(exc_info.value).startswith(
657-
"Missing required argument: 'observation_id'; Missing required argument: 'tile_id'")
658-
659-
with pytest.raises(ValueError) as exc_info:
655+
with pytest.raises(ValueError, match="Incompatible: 'observation_id' and 'tile_id'. Use only one."):
660656
tap.get_product_list(observation_id='13', tile_index='13', product_type='DpdNirStackedFrame')
661657

662-
assert str(exc_info.value).startswith("Incompatible: 'observation_id' and 'tile_id'. Use only one.")
663-
664-
with pytest.raises(ValueError) as exc_info:
658+
with pytest.raises(ValueError, match="Invalid product type DpdNirStackedFrame."):
665659
tap.get_product_list(tile_index='13', product_type='DpdNirStackedFrame')
666660

667-
assert str(exc_info.value).startswith("Invalid product type DpdNirStackedFrame.")
668-
669-
with pytest.raises(ValueError) as exc_info:
661+
with pytest.raises(ValueError, match="Missing required argument: 'product_type'"):
670662
tap.get_product_list(tile_index='13', product_type=None)
671663

672-
assert str(exc_info.value).startswith("Missing required argument: 'product_type'")
673-
674-
with pytest.raises(ValueError) as exc_info:
664+
with pytest.raises(ValueError, match="Invalid product type DpdMerBksMosaic."):
675665
tap.get_product_list(observation_id='13', product_type='DpdMerBksMosaic')
676666

677-
assert str(exc_info.value).startswith("Invalid product type DpdMerBksMosaic.")
678-
679667

680668
def test_get_product_by_product_id(tmp_path_factory):
681669
conn_handler = DummyConnHandler()
@@ -833,21 +821,15 @@ def test_get_observation_products_exceptions():
833821

834822
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
835823

836-
with pytest.raises(ValueError) as exc_info:
824+
with pytest.raises(ValueError, match="Missing required argument: 'observation_id'"):
837825
tap.get_observation_products(id=None, product_type='observation', filter='VIS', output_file=None)
838826

839-
assert str(exc_info.value).startswith("Missing required argument: 'observation_id'")
840-
841-
with pytest.raises(ValueError) as exc_info:
827+
with pytest.raises(ValueError, match="Missing required argument: 'product_type'"):
842828
tap.get_observation_products(id='12', product_type=None, filter='VIS', output_file=None)
843829

844-
assert str(exc_info.value).startswith("Missing required argument: 'product_type'")
845-
846-
with pytest.raises(ValueError) as exc_info:
830+
with pytest.raises(ValueError, match="Invalid product type XXXXXXXX. Valid values: \\['observation', 'mosaic'\\]"):
847831
tap.get_observation_products(id='12', product_type='XXXXXXXX', filter='VIS', output_file=None)
848832

849-
assert str(exc_info.value).startswith("Invalid product type XXXXXXXX. Valid values: ['observation', 'mosaic']")
850-
851833

852834
@patch.object(TapPlus, 'load_data')
853835
def test_get_observation_products_exceptions_2(mock_load_data, caplog):
@@ -929,37 +911,25 @@ def test_get_cutout_exception():
929911
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, cutout_handler=cutout_handler,
930912
show_server_messages=False)
931913

932-
with pytest.raises(Exception) as exc_info:
914+
with pytest.raises(ValueError, match="Radius cannot be greater than 30 arcminutes"):
933915
tap.get_cutout(file_path=file_path, instrument='NISP', id='19704', coordinate=c, radius=100 * u.arcmin,
934916
output_file=None)
935917

936-
assert str(exc_info.value).startswith('Radius cannot be greater than 30 arcminutes')
937-
938-
with pytest.raises(Exception) as exc_info:
918+
with pytest.raises(ValueError, match="Missing required argument"):
939919
tap.get_cutout(file_path=None, instrument='NISP', id='19704', coordinate=c, radius=r, output_file=None)
940920

941-
assert str(exc_info.value).startswith('Missing required argument')
942-
943-
with pytest.raises(Exception) as exc_info:
921+
with pytest.raises(ValueError, match="Missing required argument"):
944922
tap.get_cutout(file_path=file_path, instrument=None, id='19704', coordinate=c, radius=r, output_file=None)
945923

946-
assert str(exc_info.value).startswith('Missing required argument')
947-
948-
with pytest.raises(Exception) as exc_info:
924+
with pytest.raises(ValueError, match="Missing required argument"):
949925
tap.get_cutout(file_path=file_path, instrument='NISP', id=None, coordinate=c, radius=r, output_file=None)
950926

951-
assert str(exc_info.value).startswith('Missing required argument')
952-
953-
with pytest.raises(Exception) as exc_info:
927+
with pytest.raises(ValueError, match="Missing required argument"):
954928
tap.get_cutout(file_path=file_path, instrument='NISP', id='19704', coordinate=None, radius=r, output_file=None)
955929

956-
assert str(exc_info.value).startswith('Missing required argument')
957-
958-
with pytest.raises(Exception) as exc_info:
930+
with pytest.raises(ValueError, match="Missing required argument"):
959931
tap.get_cutout(file_path=file_path, instrument='NISP', id='19704', coordinate=c, radius=None, output_file=None)
960932

961-
assert str(exc_info.value).startswith('Missing required argument')
962-
963933

964934
@patch.object(TapPlus, 'load_data')
965935
def test_get_cutout_exceptions_2(mock_load_data, caplog):
@@ -1072,15 +1042,12 @@ def test_get_spectrum_exceptions():
10721042

10731043
# if source_id is None or schema is None:
10741044

1075-
with pytest.raises(Exception) as exc_info:
1045+
with pytest.raises(ValueError, match="Missing required argument"):
10761046
tap.get_spectrum(source_id=None, schema='sedm_sc8', output_file=None)
10771047

1078-
assert str(exc_info.value).startswith('Missing required argument')
1079-
1080-
with pytest.raises(Exception) as exc_info:
1048+
with pytest.raises(ValueError, match="Missing required argument"):
10811049
tap.get_spectrum(source_id='2417660845403252054', schema=None, output_file=None)
10821050

1083-
assert str(exc_info.value).startswith('Missing required argument')
10841051
with pytest.raises(ValueError, match=(
10851052
"Invalid argument value for 'retrieval_type'. Found hola, expected: 'ALL' or any of \\['SPECTRA_BGS', "
10861053
"'SPECTRA_RGS'\\]")):

0 commit comments

Comments
 (0)