def test_Daylight(london): d = datetime.date(2016, 1, 6) start, end = sun.daylight(london.observer, d) cstart = datetime.datetime(2016, 1, 6, 8, 5, 0, tzinfo=pytz.utc) cend = datetime.datetime(2016, 1, 6, 16, 7, 0, tzinfo=pytz.utc) assert datetime_almost_equal(start, cstart, 120) assert datetime_almost_equal(end, cend, 120)
def test_Nighttime(london): d = datetime.date(2016, 1, 6) start, end = sun.night(london.observer, d) cstart = datetime.datetime(2016, 1, 6, 16, 46, tzinfo=pytz.utc) cend = datetime.datetime(2016, 1, 7, 7, 25, tzinfo=pytz.utc) assert datetime_almost_equal(start, cstart, 120) assert datetime_almost_equal(end, cend, 120)
def test_morning(self, day, golden_hour, new_delhi): start1 = pytz.utc.localize(golden_hour[0]) end1 = pytz.utc.localize(golden_hour[1]) start2, end2 = sun.golden_hour(new_delhi.observer, day, SunDirection.RISING) assert datetime_almost_equal(end1, end2, seconds=90) assert datetime_almost_equal(start1, start2, seconds=90)
def test_Rahukaalam(day, rahu, new_delhi): start, end = rahu start = pytz.utc.localize(start) end = pytz.utc.localize(end) info = sun.rahukaalam(new_delhi.observer, day) start_utc = info[0] end_utc = info[1] assert datetime_almost_equal(start, start_utc) assert datetime_almost_equal(end, end_utc)
def test_Twilight_SunSetting(day, twilight, london): start, end = twilight start = pytz.utc.localize(start) end = pytz.utc.localize(end) info = sun.twilight(london.observer, day, direction=SunDirection.SETTING) start_utc = info[0] end_utc = info[1] assert datetime_almost_equal(start, start_utc) assert datetime_almost_equal(end, end_utc)
def test_evening(self, london): test_data = { datetime.date(2016, 5, 19): ( datetime.datetime(2016, 5, 19, 20, 18), datetime.datetime(2016, 5, 19, 20, 35), ) } for day, blue_hour in test_data.items(): start1 = pytz.utc.localize(blue_hour[0]) end1 = pytz.utc.localize(blue_hour[1]) start2, end2 = sun.blue_hour(london.observer, day, SunDirection.SETTING) assert datetime_almost_equal(end1, end2, seconds=90) assert datetime_almost_equal(start1, start2, seconds=90)
def test_Wellington(): wellington = lookup("Wellington", database()) dt = datetime.date(2020, 2, 11) tz = pytz.timezone(wellington.timezone) s = sun(wellington.observer, dt, tzinfo=tz) assert datetime_almost_equal( s["sunrise"], tz.localize(datetime.datetime(2020, 2, 11, 6, 38, 42)))
def test_TimeAtAltitude(self, new_delhi): test_data = { datetime.date(2016, 1, 5): datetime.datetime(2016, 1, 5, 10, 0) } for day, cdt in test_data.items(): cdt = new_delhi.tz.localize(cdt) dt = new_delhi.time_at_elevation(28, day) assert datetime_almost_equal(dt, cdt, seconds=600)
def test_DawnUTC(self, london): """Test Location returns dawn times in the UTC timezone""" udt = datetime.datetime(2015, 8, 1, 3, 41, 44, tzinfo=pytz.utc) dawn = london.dawn(datetime.date(2015, 8, 1), local=False) assert datetime_almost_equal(dawn, udt) assert dawn.tzinfo.zone == pytz.utc.zone
def test_Sunset(self, london): ldt = london.tz.localize(datetime.datetime(2015, 12, 1, 15, 55, 29)) sunset = london.sunset(datetime.date(2015, 12, 1)) assert datetime_almost_equal(sunset, ldt) assert sunset.tzinfo.zone == london.tzinfo.zone
def test_SunsetUTC(self, london): udt = datetime.datetime(2015, 12, 1, 15, 55, 29, tzinfo=pytz.utc) sunset = london.sunset(datetime.date(2015, 12, 1), local=False) assert datetime_almost_equal(sunset, udt) assert sunset.tzinfo.zone == pytz.utc.zone
def test_TimeAtElevation_GreaterThan90(london): d = datetime.date(2016, 1, 4) dt = sun.time_at_elevation(london.observer, 166, d, SunDirection.RISING) cdt = datetime.datetime(2016, 1, 4, 13, 20, 0, tzinfo=pytz.utc) assert datetime_almost_equal(dt, cdt, 300)
def test_DuskUTC(self, london): udt = datetime.datetime(2015, 12, 1, 16, 35, 11, tzinfo=pytz.utc) dusk = london.dusk(datetime.date(2015, 12, 1), local=False) assert datetime_almost_equal(dusk, udt) assert dusk.tzinfo.zone == pytz.utc.zone
def test_SolarNoonUTC(self, london): udt = datetime.datetime(2015, 8, 1, 12, 6, 53, tzinfo=pytz.utc) noon = london.noon(datetime.date(2015, 8, 1), local=False) assert datetime_almost_equal(noon, udt) assert noon.tzinfo.zone == pytz.utc.zone
def test_equal_with_delta(self): d1 = datetime.datetime(2019, 1, 1, 12, 0, 0) d2 = datetime.datetime(2019, 1, 1, 12, 2, 0) assert datetime_almost_equal(d1, d2, 121)
def test_SunriseUTC(self, london): udt = datetime.datetime(2015, 8, 1, 4, 23, 20, tzinfo=pytz.utc) sunrise = london.sunrise(datetime.date(2015, 8, 1), local=False) assert datetime_almost_equal(sunrise, udt) assert sunrise.tzinfo.zone == pytz.utc.zone
def test_TimeAtElevation_GreaterThan180(london): d = datetime.date(2015, 12, 1) dt = sun.time_at_elevation(london.observer, 186, d, SunDirection.RISING) cdt = datetime.datetime(2015, 12, 1, 16, 34, tzinfo=pytz.utc) assert datetime_almost_equal(dt, cdt, 300)
def test_Sun(self, london): """Test Location's version of the sun calculation""" ldt = london.tz.localize(datetime.datetime(2015, 8, 1, 5, 23, 20)) sunrise = london.sun(datetime.date(2015, 8, 1))["sunrise"] assert datetime_almost_equal(sunrise, ldt)
def test_Daylight_NoDate(london): start = pytz.utc.localize(datetime.datetime(2016, 1, 6, 8, 5, 0)) end = pytz.utc.localize(datetime.datetime(2016, 1, 6, 16, 7, 0)) ans = sun.daylight(london.observer) assert datetime_almost_equal(ans[0], start, 120) assert datetime_almost_equal(ans[1], end, 120)
def test_TimeAtElevation_SunRisingBelowHorizon(london): d = datetime.date(2016, 1, 4) dt = sun.time_at_elevation(london.observer, -18, d, SunDirection.RISING) cdt = datetime.datetime(2016, 1, 4, 6, 0, 0, tzinfo=pytz.utc) assert datetime_almost_equal(dt, cdt, 300)
def test_Dawn(self, london): """Test Location returns dawn times in the local timezone""" ldt = london.tz.localize(datetime.datetime(2015, 8, 1, 4, 41, 44)) dawn = london.dawn(datetime.date(2015, 8, 1)) assert datetime_almost_equal(dawn, ldt) assert dawn.tzinfo.zone == london.tzinfo.zone
def test_Dawn_Civil(day, dawn, london): dawn = pytz.utc.localize(dawn) dawn_utc = sun.dawn(london.observer, day, Depression.CIVIL) assert datetime_almost_equal(dawn, dawn_utc)
def test_Sunrise(self, london): ldt = london.tz.localize(datetime.datetime(2015, 8, 1, 5, 23, 20)) sunrise = london.sunrise(datetime.date(2015, 8, 1)) assert datetime_almost_equal(sunrise, ldt) assert sunrise.tzinfo.zone == london.tzinfo.zone
def test_Nighttime_NoDate(london): start = pytz.utc.localize(datetime.datetime(2016, 1, 6, 16, 46)) end = pytz.utc.localize(datetime.datetime(2016, 1, 7, 7, 25)) ans = sun.night(london.observer) assert datetime_almost_equal(ans[0], start, 300) assert datetime_almost_equal(ans[1], end, 300)
def test_SolarNoon(self, london): ldt = london.tz.localize(datetime.datetime(2015, 8, 1, 13, 6, 53)) noon = london.noon(datetime.date(2015, 8, 1)) assert datetime_almost_equal(noon, ldt) assert noon.tzinfo.zone == london.tzinfo.zone
def test_Dawn_NoDate(london): ans = pytz.utc.localize(datetime.datetime(2015, 12, 1, 7, 4)) assert datetime_almost_equal(sun.dawn(london.observer), ans)
def test_Dusk(self, london): ldt = london.tz.localize(datetime.datetime(2015, 12, 1, 16, 35, 11)) dusk = london.dusk(datetime.date(2015, 12, 1)) assert datetime_almost_equal(dusk, ldt) assert dusk.tzinfo.zone == london.tzinfo.zone
def test_Dawn_Astronomical(day, dawn, london): dawn = pytz.utc.localize(dawn) dawn_utc = sun.dawn(london.observer, day, 18) assert datetime_almost_equal(dawn, dawn_utc)
def test_equal(self): d1 = datetime.datetime(2019, 1, 1) d2 = datetime.datetime(2019, 1, 1) assert datetime_almost_equal(d1, d2)
def test_Sunrise(day, sunrise, london): sunrise = pytz.utc.localize(sunrise) sunrise_utc = sun.sunrise(london.observer, day) assert datetime_almost_equal(sunrise, sunrise_utc)