Skip to content

Commit 8fc5168

Browse files
committed
added unit tests for code cov
1 parent 7bf8b9b commit 8fc5168

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

astroquery/mast/tests/test_mast_remote.py

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,8 @@ def test_tesscut_get_sectors(self, product):
787787

788788
def test_tesscut_get_sectors_mt(self):
789789

790-
# Moving target functionality testing (defaults to SPOC)
790+
# Moving target functionality testing
791+
791792
coord = SkyCoord(349.62609, -47.12424, unit="deg")
792793
moving_target_name = 'Eleonora'
793794

@@ -806,6 +807,7 @@ def test_tesscut_get_sectors_mt(self):
806807
error_nameresolve = f"Could not resolve {moving_target_name} to a sky position."
807808
error_mt_coord = "Only one of moving_target and coordinates may be specified."
808809
error_name_coord = "Only one of objectname and coordinates may be specified."
810+
error_tica_mt = "Only SPOC is available for moving targets queries."
809811

810812
with pytest.raises(InvalidQueryError) as error_msg:
811813
mast.Tesscut.get_sectors(moving_target=True)
@@ -830,25 +832,19 @@ def test_tesscut_get_sectors_mt(self):
830832
moving_target=True)
831833
assert error_mt_coord in str(error_msg.value)
832834

833-
# The TICA product option is not available for moving targets. This should default to SPOC.
834-
835-
moving_target_name = 'Eleonora'
835+
# The TICA product option is not available for moving targets
836836

837-
with pytest.warns(InputWarning):
837+
with pytest.raises(InvalidQueryError) as error_msg:
838838
sector_table = mast.Tesscut.get_sectors(objectname=moving_target_name, product='tica',
839839
moving_target=True)
840-
assert isinstance(sector_table, Table)
841-
assert len(sector_table) >= 1
842-
assert "tess-s00" in sector_table['sectorName'][0]
843-
assert sector_table['sector'][0] > 0
844-
assert sector_table['camera'][0] > 0
845-
assert sector_table['ccd'][0] > 0
840+
assert error_msg in str(error_msg.value)
846841

847-
def test_tesscut_download_cutouts(self, tmpdir):
842+
@pytest.mark.parametrize("product", ["tica", "spoc"])
843+
def test_tesscut_download_cutouts(self, tmpdir, product):
848844

849845
coord = SkyCoord(349.62609, -47.12424, unit="deg")
850846

851-
manifest = mast.Tesscut.download_cutouts(coordinates=coord, size=5, path=str(tmpdir))
847+
manifest = mast.Tesscut.download_cutouts(product=product, coordinates=coord, size=5, path=str(tmpdir))
852848
assert isinstance(manifest, Table)
853849
assert len(manifest) >= 1
854850
assert manifest["Local Path"][0][-4:] == "fits"
@@ -857,34 +853,38 @@ def test_tesscut_download_cutouts(self, tmpdir):
857853

858854
coord = SkyCoord(107.18696, -70.50919, unit="deg")
859855

860-
manifest = mast.Tesscut.download_cutouts(coordinates=coord, size=5, sector=1, path=str(tmpdir))
856+
manifest = mast.Tesscut.download_cutouts(product=product, coordinates=coord, size=5, sector=27, path=str(tmpdir))
861857
assert isinstance(manifest, Table)
862858
assert len(manifest) == 1
863859
assert manifest["Local Path"][0][-4:] == "fits"
864860
assert os.path.isfile(manifest[0]['Local Path'])
865861

866-
manifest = mast.Tesscut.download_cutouts(coordinates=coord, size=[5, 7]*u.pix, sector=8, path=str(tmpdir))
862+
manifest = mast.Tesscut.download_cutouts(product=product, coordinates=coord, size=[5, 7]*u.pix, sector=33,
863+
path=str(tmpdir))
867864
assert isinstance(manifest, Table)
868865
assert len(manifest) >= 1
869866
assert manifest["Local Path"][0][-4:] == "fits"
870867
for row in manifest:
871868
assert os.path.isfile(row['Local Path'])
872869

873-
manifest = mast.Tesscut.download_cutouts(coordinates=coord, size=5, sector=8, path=str(tmpdir), inflate=False)
870+
manifest = mast.Tesscut.download_cutouts(product=product, coordinates=coord, size=5, sector=33, path=str(tmpdir),
871+
inflate=False)
874872
assert isinstance(manifest, Table)
875873
assert len(manifest) == 1
876874
assert manifest["Local Path"][0][-3:] == "zip"
877875
assert os.path.isfile(manifest[0]['Local Path'])
878876

879-
manifest = mast.Tesscut.download_cutouts(objectname="TIC 32449963", size=5, path=str(tmpdir))
877+
manifest = mast.Tesscut.download_cutouts(product=product, objectname="TIC 32449963", size=5, path=str(tmpdir))
880878
assert isinstance(manifest, Table)
881879
assert len(manifest) >= 1
882880
assert manifest["Local Path"][0][-4:] == "fits"
883881
for row in manifest:
884882
assert os.path.isfile(row['Local Path'])
885883

886-
# Moving target functionality testing
884+
def test_tesscut_download_cutouts_mt(self, tmpdir):
887885

886+
# Moving target functionality testing
887+
coord = SkyCoord(349.62609, -47.12424, unit="deg")
888888
moving_target_name = 'Eleonora'
889889

890890
manifest = mast.Tesscut.download_cutouts(objectname=moving_target_name,
@@ -928,34 +928,44 @@ def test_tesscut_download_cutouts(self, tmpdir):
928928
moving_target=True)
929929
assert error_mt_coord in str(error_msg.value)
930930

931-
def test_tesscut_get_cutouts(self, tmpdir):
931+
# The TICA product option is not available for moving targets
932+
933+
with pytest.raises(InvalidQueryError) as error_msg:
934+
mast.Tesscut.download_cutouts(objectname=moving_target_name, product='tica',
935+
moving_target=True)
936+
assert error_msg in str(error_msg.value)
937+
938+
@pytest.mark.parametrize("product", ["tica", "spoc"])
939+
def test_tesscut_get_cutouts(self, product):
932940

933941
coord = SkyCoord(107.18696, -70.50919, unit="deg")
934942

935-
cutout_hdus_list = mast.Tesscut.get_cutouts(coordinates=coord, size=5, sector=8,)
943+
cutout_hdus_list = mast.Tesscut.get_cutouts(product=product, coordinates=coord, size=5, sector=33)
936944
assert isinstance(cutout_hdus_list, list)
937945
assert len(cutout_hdus_list) >= 1
938946
assert isinstance(cutout_hdus_list[0], fits.HDUList)
939947

940-
cutout_hdus_list = mast.Tesscut.get_cutouts(coordinates=coord, size=5, sector=1)
948+
cutout_hdus_list = mast.Tesscut.get_cutouts(product=product, coordinates=coord, size=5, sector=27)
941949
assert isinstance(cutout_hdus_list, list)
942950
assert len(cutout_hdus_list) == 1
943951
assert isinstance(cutout_hdus_list[0], fits.HDUList)
944952

945953
coord = SkyCoord(349.62609, -47.12424, unit="deg")
946954

947-
cutout_hdus_list = mast.Tesscut.get_cutouts(coordinates=coord, size=[2, 4]*u.arcmin)
955+
cutout_hdus_list = mast.Tesscut.get_cutouts(product=product, coordinates=coord, size=[2, 4]*u.arcmin)
948956
assert isinstance(cutout_hdus_list, list)
949957
assert len(cutout_hdus_list) >= 1
950958
assert isinstance(cutout_hdus_list[0], fits.HDUList)
951959

952-
cutout_hdus_list = mast.Tesscut.get_cutouts(objectname="TIC 32449963", size=5)
960+
cutout_hdus_list = mast.Tesscut.get_cutouts(product=product, objectname="TIC 32449963", size=5)
953961
assert isinstance(cutout_hdus_list, list)
954962
assert len(cutout_hdus_list) >= 1
955963
assert isinstance(cutout_hdus_list[0], fits.HDUList)
956964

957-
# Moving target functionality testing
965+
def test_tesscut_get_cutouts_mt(self):
958966

967+
# Moving target functionality testing
968+
coord = SkyCoord(349.62609, -47.12424, unit="deg")
959969
moving_target_name = 'Eleonora'
960970

961971
cutout_hdus_list = mast.Tesscut.get_cutouts(objectname=moving_target_name,
@@ -974,28 +984,35 @@ def test_tesscut_get_cutouts(self, tmpdir):
974984
error_name_coord = "Only one of objectname and coordinates may be specified."
975985

976986
with pytest.raises(InvalidQueryError) as error_msg:
977-
mast.Tesscut.download_cutouts(moving_target=True)
987+
mast.Tesscut.get_cutouts(moving_target=True)
978988
assert error_noname in str(error_msg.value)
979989

980990
with pytest.raises(ResolverError) as error_msg:
981-
mast.Tesscut.download_cutouts(objectname=moving_target_name)
991+
mast.Tesscut.get_cutouts(objectname=moving_target_name)
982992
assert error_nameresolve in str(error_msg.value)
983993

984994
with pytest.raises(InvalidQueryError) as error_msg:
985-
mast.Tesscut.download_cutouts(coordinates=coord, moving_target=True)
995+
mast.Tesscut.get_cutouts(coordinates=coord, moving_target=True)
986996
assert error_mt_coord in str(error_msg.value)
987997

988998
with pytest.raises(InvalidQueryError) as error_msg:
989-
mast.Tesscut.download_cutouts(objectname=moving_target_name,
999+
mast.Tesscut.get_cutouts(objectname=moving_target_name,
9901000
coordinates=coord)
9911001
assert error_name_coord in str(error_msg.value)
9921002

9931003
with pytest.raises(InvalidQueryError) as error_msg:
994-
mast.Tesscut.download_cutouts(objectname=moving_target_name,
1004+
mast.Tesscut.get_cutouts(objectname=moving_target_name,
9951005
coordinates=coord,
9961006
moving_target=True)
9971007
assert error_mt_coord in str(error_msg.value)
9981008

1009+
# The TICA product option is not available for moving targets
1010+
1011+
with pytest.raises(InvalidQueryError) as error_msg:
1012+
mast.Tesscut.get_cutouts(objectname=moving_target_name, product='tica',
1013+
moving_target=True)
1014+
assert error_msg in str(error_msg.value)
1015+
9991016
###################
10001017
# ZcutClass tests #
10011018
###################

0 commit comments

Comments
 (0)