def test_same_doy_is_equal(self, execution_number, random_date): other_year = random.randint(500, 3000) shift_day = datetime.timedelta(days=0) this_date = random_date if isleap(this_date.year) != isleap( other_year) and this_date > datetime.date( this_date.year, 2, 28): if isleap(other_year): shift_day = datetime.timedelta(days=-1) else: shift_day = datetime.timedelta(days=1) if (isleap(this_date.year) and not isleap(other_year) and this_date.month == 2 and this_date.day == 29): # Special case we can't simply replace the year as there's # no leap day in the other year other_date = datetime.date(other_year, 3, 1) else: other_date = this_date.replace(year=other_year) + shift_day this_zmanim = Zmanim(this_date).get_utc_sun_time_full() other_zmanim = Zmanim(other_date).get_utc_sun_time_full() grace = 0 if not _ASTRAL else 14 for key, value in this_zmanim.items(): assert value - grace <= other_zmanim[key] <= value + grace, key
def test_same_doy_is_equal(self, execution_number, random_date): other_year = random.randint(500, 3000) shift_day = datetime.timedelta(days=0) this_date = random_date if isleap(this_date.year) != isleap(other_year) and this_date > datetime.date( this_date.year, 2, 28 ): if isleap(other_year): shift_day = datetime.timedelta(days=-1) else: shift_day = datetime.timedelta(days=1) if ( isleap(this_date.year) and not isleap(other_year) and this_date.month == 2 and this_date.day == 29 ): # Special case we can't simply replace the year as there's # no leap day in the other year other_date = datetime.date(other_year, 3, 1) else: other_date = this_date.replace(year=other_year) + shift_day assert ( Zmanim(this_date).get_utc_sun_time_full() == Zmanim(other_date).get_utc_sun_time_full() )
def test_using_tzinfo(self): day = datetime.date(2018, 9, 8) timezone_str = "America/New_York" timezone = pytz.timezone(timezone_str) location_tz_str = Location( name="New York", latitude=NYC_LAT, longitude=NYC_LNG, timezone=timezone_str, diaspora=True, ) location = Location( name="New York", latitude=NYC_LAT, longitude=NYC_LNG, timezone=timezone, diaspora=True, ) compare_times( Zmanim(date=day, location=location_tz_str).zmanim["first_stars"].time(), datetime.time(19, 45)) compare_times( Zmanim(date=day, location=location).zmanim["first_stars"].time(), datetime.time(19, 45))
def test_issur_melacha_motsaei_pesach_ii(self): c = Location( name="New York", latitude=40.7128, longitude=-74.0060, timezone="America/New_York", diaspora=True, ) z = Zmanim(date=datetime(2019, 4, 21, 20, 30), location=c) assert not z.issur_melacha_in_effect
def test_erev_shabbat_hag(self, now, offset, erev_shabbat_chag): location_tz_str = Location( name="New York", latitude=NYC_LAT, longitude=NYC_LNG, timezone="America/New_York", diaspora=True, ) # Use a constant offset for Havdalah for unit test stability. zmanim = Zmanim(date=now, location=location_tz_str, havdalah_offset=offset) assert zmanim.erev_shabbat_chag == erev_shabbat_chag
def test_zmanim_localized_datetime(self): c = Location( name="New York", latitude=40.7128, longitude=-74.0060, timezone="America/New_York", diaspora=True, ) z = Zmanim(date=c.timezone.localize(datetime(2019, 4, 21, 20, 30)), location=c) assert not z.issur_melacha_in_effect
def test_using_tzinfo(self): day = datetime.date(2018, 9, 8) timezone_str = "America/New_York" timezone = tz.gettz(timezone_str) location_tz_str = Location(name="New York", latitude=NYC_LAT, longitude=NYC_LNG, timezone=timezone_str, diaspora=True) location = Location(name="New York", latitude=NYC_LAT, longitude=NYC_LNG, timezone=timezone, diaspora=True) assert (Zmanim(date=day, location=location_tz_str).zmanim["first_stars"].time() == datetime.time(19, 48)) assert (Zmanim( date=day, location=location).zmanim["first_stars"].time() == datetime.time( 19, 48))
def test_havdalah(self, now, offset, havdalah, melacha_assur): location_tz_str = Location( name="New York", latitude=NYC_LAT, longitude=NYC_LNG, timezone="America/New_York", diaspora=True, ) # Use a constant offset for Havdalah for unit test stability. zmanim = Zmanim(date=now, location=location_tz_str, havdalah_offset=offset) actual = zmanim.havdalah if actual is not None: actual = actual.replace(tzinfo=None) compare_dates(actual, havdalah) assert zmanim.issur_melacha_in_effect == melacha_assur
def test_candle_lighting(self, now, offset, candle_lighting, melacha_assur): location_tz_str = Location(name="New York", latitude=NYC_LAT, longitude=NYC_LNG, timezone="America/New_York", diaspora=True) # Use a constant offset for Havdalah for unit test stability. zmanim = Zmanim(date=now, location=location_tz_str, candle_lighting_offset=offset, havdalah_offset=42) actual = zmanim.candle_lighting if actual is not None: actual = actual.replace(tzinfo=None) assert actual == candle_lighting assert zmanim.issur_melacha_in_effect == melacha_assur
def test_readme_example_english(self, capsys): c = Location("פתח תקוה", 32.08707, 34.88747, "Asia/Jerusalem", 54) z = Zmanim(date=date(2016, 4, 18), location=c, hebrew=False) print(z) captured = capsys.readouterr() assert (captured.out == "Alot HaShachar - 04:53:00\n" "Talit & Tefilin's time - 05:19:00\n" "Sunrise - 06:09:00\n" 'Shema EOT MG"A - 08:46:00\n' 'Shema EOT GR"A - 09:24:00\n' 'Tefila EOT MG"A - 10:03:40\n' 'Tefila EOT GR"A - 10:29:00\n' "Midday - 12:39:00\n" "Big Mincha - 13:11:30\n" "Small Mincha - 16:26:30\n" "Plag Mincha - 17:48:45\n" "Sunset - 19:10:00\n" "First stars - 19:35:00\n" "Midnight - 00:39:00\n\n")
def test_readme_example_hebrew(self, capsys): c = Location("פתח תקוה", 32.08707, 34.88747, "Asia/Jerusalem", 54) z = Zmanim(date=date(2016, 4, 18), location=c) print(z) captured = capsys.readouterr() assert (captured.out == u"עלות השחר - 04:53:00\n" u"זמן טלית ותפילין - 05:19:00\n" u"הנץ החמה - 06:09:00\n" u'סוף זמן ק"ש מג"א - 08:46:00\n' u'סוף זמן ק"ש הגר"א - 09:24:00\n' u'סוף זמן תפילה מג"א - 10:03:40\n' u'סוף זמן תפילה גר"א - 10:29:00\n' u"חצות היום - 12:39:00\n" u"מנחה גדולה - 13:11:30\n" u"מנחה קטנה - 16:26:30\n" u"פלג מנחה - 17:48:45\n" u"שקיעה - 19:10:00\n" u"צאת הככבים - 19:35:00\n" u"חצות הלילה - 00:39:00\n\n")
def test_readme_example_hebrew(self, capsys): c = Location("פתח תקוה", 32.08707, 34.88747, "Asia/Jerusalem", 54) z = Zmanim(date=date(2016, 4, 18), location=c) print(z) captured = capsys.readouterr() if not _ASTRAL: return assert (captured.out == u"עלות השחר - 04:52:00\n" u"זמן טלית ותפילין - 05:18:00\n" u"הנץ החמה - 06:08:00\n" u'סוף זמן ק"ש מג"א - 08:46:00\n' u'סוף זמן ק"ש גר"א - 09:23:00\n' u'סוף זמן תפילה מג"א - 10:04:00\n' u'סוף זמן תפילה גר"א - 10:28:00\n' u"חצות היום - 12:40:00\n" u"מנחה גדולה - 13:10:30\n" u"מנחה קטנה - 16:25:30\n" u"פלג המנחה - 17:50:45\n" u"שקיעה - 19:12:00\n" u"צאת הכוכבים - 19:38:00\n" u"חצות הלילה - 00:40:00\n\n")
def test_bad_date(self): with pytest.raises(TypeError): Zmanim(date="bad value")
def test_issur_melacha_weekday(self): c = Location("פתח תקוה", 32.08707, 34.88747, "Asia/Jerusalem", 54) z = Zmanim(date=date(2018, 11, 12), location=c) assert not z.issur_melacha_in_effect
def test_issur_melacha_motsaei_shavuot(self): c = Location("פתח תקוה", 32.08707, 34.88747, "Asia/Jerusalem", 54) z = Zmanim(date=datetime(2019, 6, 9, 20, 30), location=c) assert not z.issur_melacha_in_effect
def test_issur_melacha_shavuot_evening(self): c = Location("פתח תקוה", 32.08707, 34.88747, "Asia/Jerusalem", 54) z = Zmanim(date=datetime(2019, 6, 8, 21, 45), location=c) assert z.issur_melacha_in_effect
def test_issur_melacha_pesach_vi_mornng(self): c = Location("פתח תקוה", 32.08707, 34.88747, "Asia/Jerusalem", 54) z = Zmanim(date=datetime(2019, 4, 25, 9, 45), location=c) assert not z.issur_melacha_in_effect
def test_issur_melacha_motsaei_shabbat(self): c = Location("פתח תקוה", 32.08707, 34.88747, "Asia/Jerusalem", 54) z = Zmanim(date=datetime(2018, 11, 10, 17, 45), location=c) assert not z.issur_melacha_in_effect
def test_issur_melacha_friday_evening(self): c = Location("פתח תקוה", 32.08707, 34.88747, "Asia/Jerusalem", 54) z = Zmanim(date=datetime(2018, 11, 9, 16, 45), location=c) assert z.issur_melacha_in_effect