Skip to content

Commit

Permalink
specify order of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed May 7, 2024
1 parent 21a3dc4 commit 106cfff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 7 additions & 7 deletions py/desiutil/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions py/desiutil/test/test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")

0 comments on commit 106cfff

Please sign in to comment.