def test_galsim_range_error(): """Test basic usage of GalSimRangeError """ value = 2.3 err = galsim.GalSimRangeError("Test", value, 0, 1) print('str = ', str(err)) print('repr = ', repr(err)) assert str(err) == "Test Value 2.3 not in range [0, 1]" assert err.value == value assert err.min == 0 assert err.max == 1 assert isinstance(err, galsim.GalSimError) assert isinstance(err, ValueError) do_pickle(err) err = galsim.GalSimRangeError("Test", value, 10) print('str = ', str(err)) print('repr = ', repr(err)) assert str(err) == "Test Value 2.3 not in range [10, None]" assert err.value == value assert err.min == 10 assert err.max == None assert isinstance(err, galsim.GalSimError) assert isinstance(err, ValueError) do_pickle(err)
def _parse_SCAs(SCAs): # This is a helper routine to parse the input SCAs (single number or iterable) and put it into a # convenient format. It is used in wfirst_wcs.py. # # Check which SCAs are to be done. Default is all (and they are 1-indexed). all_SCAs = np.arange(1, n_sca + 1, 1) # Later we will use the list of selected SCAs to decide which ones we're actually going to do # the calculations for. For now, just check for invalid numbers. if SCAs is not None: # Make sure SCAs is iterable. if not hasattr(SCAs, '__iter__'): SCAs = [SCAs] # Then check for reasonable values. if min(SCAs) <= 0 or max(SCAs) > galsim.wfirst.n_sca: raise galsim.GalSimRangeError("Invalid SCA.", SCAs, 1, galsim.wfirst.n_sca) # Check for uniqueness. If not unique, make it unique. SCAs = list(set(SCAs)) else: SCAs = all_SCAs return SCAs