def setUp(self): self.daytime1 = Daytime.fromtime(time(0, 0, 0, 8000)) self.daytime2 = Daytime.strptime('2,20,22,007000', '%H,%M,%S,%f') self.daytime3 = Daytime.utcfromtimestamp( Daytime(2, 20, 23, 90000).as_seconds) self.daytime4 = Daytime.fromtimestamp( Daytime(12, 25, 0, 8400).as_seconds, UTC()) self.daytime5 = Daytime(18, 43, 20, 6000) self.daytime6 = Daytime.daytime
def test_day_night(): with open('tests/day-night.json', 'r') as f: day_night_results = json.load(f) year = 2018 months = range(3, 13, 3) hours = range(24) minute = 0 day = 21 locations = { "north_pole": (90, 0), "south_pole": (-90, 0), "greenwich": (51.48, 0) } for location, coords in locations.items(): for month in months: for hour in hours: time = ephem.Date((year, month, day, hour, minute)) dark = Daytime(coords).dark_outside(time) assert dark == day_night_results[location + " " + str( time )], "expected it to be {} on {} at {} (coords:{}), got opposite.".format( "dark" if dark else "not dark", time, location, coords)
def __init__(self, location, debug=False): self._debug = debug self._lifxlan = LifxLAN() self._daytime = Daytime(location)