From 106cfff45bcbfa3d241b6e02904d3b8cb0b5ecc1 Mon Sep 17 00:00:00 2001 From: Benjamin Alan Weaver Date: Tue, 7 May 2024 15:54:07 -0700 Subject: [PATCH] specify order of tests --- py/desiutil/names.py | 14 +++++++------- py/desiutil/test/test_names.py | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/py/desiutil/names.py b/py/desiutil/names.py index cd92f79..fe56799 100644 --- a/py/desiutil/names.py +++ b/py/desiutil/names.py @@ -43,14 +43,14 @@ def radec_to_desiname(target_ra, target_dec): target_ra, target_dec = np.atleast_1d(target_ra), np.atleast_1d(target_dec) inputs = {'target_ra': target_ra, 'target_dec': target_dec} - tests = {'NaN values': np.isnan, - 'Infinite values': np.isinf, - 'RA not in range [0, 360)': lambda x: (x < 0) | (x >= 360), - 'Dec not in range [-90, 90]': lambda x: (x < -90) | (x > 90)} + tests = (('NaN values', np.isnan), + ('Infinite values', np.isinf), + ('RA not in range [0, 360)', lambda x: (x < 0) | (x >= 360)), + ('Dec not in range [-90, 90]', lambda x: (x < -90) | (x > 90))) for i in inputs: - for t in tests: - if (tests[t](inputs[i])).any(): - raise ValueError(f"{t} detected in {i}!") + for key, check in tests: + if (check(inputs[i])).any(): + raise ValueError(f"{key} detected in {i}!") # Number of decimal places in final naming convention precision = 4 diff --git a/py/desiutil/test/test_names.py b/py/desiutil/test/test_names.py index d7148db..49ab2f6 100644 --- a/py/desiutil/test/test_names.py +++ b/py/desiutil/test/test_names.py @@ -56,3 +56,8 @@ def test_radec_to_desiname_bad_values(self): with self.assertRaises(ValueError) as e: outnames = radec_to_desiname(ras, decs) self.assertEqual(str(e.exception), "NaN values detected in target_ra!") + + ras[2] = np.inf + with self.assertRaises(ValueError) as e: + outnames = radec_to_desiname(ras, decs) + self.assertEqual(str(e.exception), "Infinite values detected in target_ra!")