def test_from_altaz_parameters(): usno = api.earth.topos('38.9215 N', '77.0669 W', elevation_m=92.0) p = usno(tt=api.T0) a = api.Angle(degrees=10.0) with assert_raises(ValueError, 'the alt= parameter with an Angle'): p.from_altaz(alt='Bad value', alt_degrees=0, az_degrees=0) with assert_raises(ValueError, 'the az= parameter with an Angle'): p.from_altaz(az='Bad value', alt_degrees=0, az_degrees=0) p.from_altaz(alt=a, alt_degrees='bad', az_degrees=0) p.from_altaz(az=a, alt_degrees=0, az_degrees='bad')
def test_from_altaz_parameters(ts): e = api.load('de421.bsp') usno = e['earth'].topos('38.9215 N', '77.0669 W', elevation_m=92.0) jd = ts.tt(api.T0) p = usno.at(jd) a = api.Angle(degrees=10.0) with assert_raises(ValueError, 'the alt= parameter with an Angle'): p.from_altaz(alt='Bad value', alt_degrees=0, az_degrees=0) with assert_raises(ValueError, 'the az= parameter with an Angle'): p.from_altaz(az='Bad value', alt_degrees=0, az_degrees=0) p.from_altaz(alt=a, alt_degrees='bad', az_degrees=0) p.from_altaz(az=a, alt_degrees=0, az_degrees='bad')
def test_tuple_error_raised(): def fake_function(): """ The decorator requires a docstring. """ decorated_function = takes_julian_date(fake_function) tuple_argument = (2014, 1, 23) self = None with assert_raises(ValueError) as info: decorated_function(self, tuple_argument) assert 'Are you trying to pass in a tuple' in str(info.exception)
def test_iterating_over_raw_velocity(): velocity = units.Velocity(au_per_d=1.234) with assert_raises(units.UnpackingError): x, y, z = velocity
def test_bad_addition(): planets = load('de421.bsp') earth = planets['earth'] mars = planets['mars'] with assert_raises(ValueError, 'the center where the other vector starts'): earth + mars
def test_sending_jd_that_is_not_a_julian_date(): earth = api.load('de421.bsp')['earth'] with assert_raises(ValueError, 'your "jd" argument is not a JulianDate: '): earth.at('blah')
def test_named_star_throws_valueerror(): with assert_raises(ValueError, 'No star named foo known to skyfield'): api.NamedStar('foo')
def test_that_building_time_from_naive_datetime_raises_exception(ts): with assert_raises(ValueError) as info: ts.from_datetime(datetime(1973, 12, 29, 23, 59, 48)) assert 'import timezone' in str(info.exception)
def test_raises3(): with assert_raises(ValueError, 'correct message but wrong exception'): raise KeyError('correct message but wrong exception')
def test_building_JulianDate_from_naive_datetime_raises_exception(): with assert_raises(ValueError) as info: JulianDate(utc=datetime(1973, 12, 29, 23, 59, 48)) assert 'import timezone' in str(info.exception)
def test_build_url(load): url = 'ftp://ssd.jpl.nasa.gov/pub/eph/planets/bsp/de421.bsp' assert load.build_url('de421.bsp') == url with assert_raises(ValueError, 'know the URL'): load.build_url('unknown.kind.of.file')
def test_altaz_needs_topos(ts): e = api.load('de421.bsp') earth = e['earth'] moon = e['moon'] with assert_raises(ValueError, 'using a Topos instance'): earth.at(ts.utc(2016)).observe(moon).apparent().altaz()
def test_iterating_over_raw_angle(): angle = Angle(degrees=4.5) with assert_raises(ValueError) as a: iter(angle) assert str(a.exception) == '''choose a specific Angle unit to iterate over
def test_iterating_over_raw_velocity(): velocity = Velocity(au_per_d=1.234) with assert_raises(UnpackingError) as a: x, y, z = velocity assert str(a.exception) == '''\
def test_iterating_over_raw_measurement(): distance = Distance(au=1.234) with assert_raises(UnpackingError) as a: x, y, z = distance assert str(a.exception) == '''\
def test_sending_jd_that_is_not_a_julian_date(): with assert_raises(ValueError, 'your "jd" argument is not a JulianDate: '): api.earth('blah')
def test_from_altaz_needs_topos(): p = positionlib.ICRF([0.0, 0.0, 0.0]) with assert_raises(ValueError, 'to compute an altazimuth position'): p.from_altaz(alt_degrees=0, az_degrees=0)
def test_sending_jd_that_is_not_a_julian_date(): return # TODO: turn this back on, using one of the new ts method calls earth = api.load('de421.bsp')['earth'] with assert_raises(ValueError, 'your "jd" argument is not a JulianDate: '): earth.at('blah')
def test_iterating_over_raw_measurement(): distance = units.Distance(au=1.234) with assert_raises(units.UnpackingError): x, y, z = distance
def test_raises1(): with assert_raises(ValueError): raise ValueError('irrelevant message')
def test_raises2(): with assert_raises(ValueError, 'correct message'): raise ValueError('correct message')
def test_raises4(): with assert_raises(ValueError, 'one message'): raise ValueError('another message')
def test_from_altaz_needs_topos(): p = positionlib.ICRF([0.0, 0.0, 0.0]) with assert_raises(ValueError, 'the orientation of the horizon'): p.from_altaz(alt_degrees=0, az_degrees=0)
def test_altaz_needs_topos(ts): e = api.load('de421.bsp') earth = e['earth'] moon = e['moon'] with assert_raises(ValueError, 'from a specific Earth location'): earth.at(ts.utc(2016)).observe(moon).apparent().altaz()
def test_building_JulianDate_from_naive_datetime_raises_exception(): with assert_raises(ValueError) as info: JulianDate(utc=datetime(1973, 12, 29, 23, 59, 48)) assert "import timezone" in str(info.exception)
def test_bad_subtraction(): planets = load('de421.bsp') earth = planets['earth'] usno = Topos('38.9215 N', '77.0669 W', elevation_m=92.0) with assert_raises(ValueError, 'if they both start at the same center'): earth - usno
def test_that_building_time_from_naive_datetime_raises_exception(ts): with assert_raises(ValueError) as info: ts.utc(datetime(1973, 12, 29, 23, 59, 48)) assert 'import timezone' in str(info.exception)
def test_from_altaz_needs_topos(): p = positionlib.ICRS([0.0, 0.0, 0.0]) with assert_raises(ValueError, 'the orientation of the horizon'): p.from_altaz(alt_degrees=0, az_degrees=0)
def test_non_builtin_timescale_tries_to_load_finals2000A_all(load): save_file(load, 'finals2000A.all', b'invalid data') with assert_raises(IndexError): load.timescale(builtin=False)