def test_assign_bad_hdate_value(self): bad_day_value = HebrewDate(5779, 10, 35) with pytest.raises(TypeError): HDate().hdate = "not a HebrewDate" with pytest.raises(ValueError): HebrewDate(5779, 15, 3) with pytest.raises(ValueError): HDate().hdate = bad_day_value
def test_get_reading_diaspora(self, year, parshiyot): mydate = HDate(hebrew=False, diaspora=True) mydate.hdate = HebrewDate(year, 1, 1) # Get next Saturday tdelta = datetime.timedelta((12 - mydate.gdate.weekday()) % 7) mydate.gdate += tdelta shabatot = [item for subl in parshiyot for item in subl] for shabat in shabatot: print("Testing: ", mydate) assert mydate.get_reading() == shabat mydate.gdate += datetime.timedelta(days=7) mydate.hdate = HebrewDate(year, 1, 23) # VeZot Habracha in Israel always falls on 22 of Tishri assert mydate.get_reading() == 54
def test_get_diaspora_israel_holidays(self, rand_hdate, date, diaspora_holiday, israel_holiday): rand_hdate.hdate = HebrewDate(rand_hdate.hdate.year, date[1], date[0]) assert rand_hdate.holiday_name == israel_holiday rand_hdate.diaspora = True assert rand_hdate.holiday_name == diaspora_holiday assert rand_hdate.is_holiday
def test_get_holiday_hanuka_3rd_tevet(self): year = random.randint(5000, 6000) year_size = conv.get_size_of_hebrew_year(year) myhdate = HDate(heb_date=HebrewDate(year, 4, 3)) print(year_size) if year_size in [353, 383]: assert myhdate.holiday_name == "chanukah" else: assert myhdate.holiday_name == ""
def test_vayelech_or_haazinu_always_after_rosh_hashana(self, year): mydate = HDate(hebrew=False, diaspora=True) mydate.hdate = HebrewDate(year, Months.Tishrei, 1) tdelta = datetime.timedelta((12 - mydate.gdate.weekday()) % 7) # Go to the next shabbat (unless shabbat falls on Rosh Hashana) mydate.gdate += tdelta print("Testing date: {} which is {} days after Rosh Hashana".format( mydate, tdelta)) assert mydate.get_reading() in [52, 53, 0]
def test_nitzavim_always_before_rosh_hashana(self, year): mydate = HDate(hebrew=False, diaspora=False) mydate.hdate = HebrewDate(year, Months.Tishrei, 1) tdelta = datetime.timedelta((12 - mydate.gdate.weekday()) % 7 - 7) # Go back to the previous shabbat mydate.gdate += tdelta print("Testing date: {} which is {} days before Rosh Hashana".format( mydate, tdelta)) assert mydate.get_reading() in [51, 61]
def test_get_omer_day(self, execution_number, rand_hdate): if (rand_hdate.hdate.month not in [7, 8, 9] or rand_hdate.hdate.month == 7 and rand_hdate.hdate.day < 16 or rand_hdate.hdate.month == 9 and rand_hdate.hdate.day > 5): assert rand_hdate.omer_day == 0 nissan = list(range(16, 30)) iyyar = list(range(1, 29)) sivan = list(range(1, 5)) for day in nissan: rand_hdate.hdate = HebrewDate(rand_hdate.hdate.year, 7, day) assert rand_hdate.omer_day == day - 15 for day in iyyar: rand_hdate.hdate = HebrewDate(rand_hdate.hdate.year, 8, day) assert rand_hdate.omer_day == day + 15 for day in sivan: rand_hdate.hdate = HebrewDate(rand_hdate.hdate.year, 9, day) assert rand_hdate.omer_day == day + 44
def test_new_holidays_invalid_before(self, possible_dates, years, holiday): # Yom hazikaron and yom ha'atsmaut don't test for before 5764 if years[0] == 5764 and holiday in ['yom_hazikaron', 'yom_haatzmaut']: return year = random.randint(5000, years[0] - 1) print("Testing " + holiday + " for " + str(year)) for date in possible_dates: date_under_test = HDate() date_under_test.hdate = HebrewDate(year, date[1], date[0]) assert date_under_test.holiday_name == ""
def test_new_holidays_multiple_date(self, possible_dates, years, holiday): found_matching_holiday = False year = random.randint(*years) print("Testing " + holiday + " for " + str(year)) for date in possible_dates: date_under_test = HDate(hebrew=False) date_under_test.hdate = HebrewDate(year, date[1], date[0]) if date_under_test.holiday_name == holiday: print("date ", date_under_test, " matched") for other in possible_dates: if other != date: other_date = HDate(hebrew=False) other_date.hdate = HebrewDate(year, other[1], other[0]) print("checking ", other_date, " doesn't match") assert other_date.holiday_name != holiday found_matching_holiday = True assert date_under_test.is_holiday assert found_matching_holiday
def test_get_holiday_adar(self, possible_days, holiday): year = random.randint(5000, 6000) year_size = conv.get_size_of_hebrew_year(year) month = 6 if year_size < 360 else 14 myhdate = HDate() for day in possible_days: myhdate.hdate = HebrewDate(year, month, day) if day == 13 and myhdate.dow == 7 and holiday == "taanit_esther": assert myhdate.holiday_name == "" elif day == 11 and myhdate.dow != 5 and holiday == "taanit_esther": assert myhdate.holiday_name == "" else: assert myhdate.holiday_name == holiday
def test_upcoming_shabbat(self, current_date, shabbat_date, hebrew_date): hd = HDate(gdate=datetime.date(*current_date)) assert hd.hdate == HebrewDate(*hebrew_date) next_shabbat = hd.upcoming_shabbat assert next_shabbat.gdate == datetime.date(*shabbat_date)
def test_pesach_day_of_week(self, rand_hdate): for year, info in list(HEBREW_YEARS_INFO.items()): rand_hdate.hdate = HebrewDate(year, 7, 15) assert rand_hdate.dow == info[2] assert rand_hdate.holiday_name == "pesach"
def test_rosh_hashana_day_of_week(self, rand_hdate): for year, info in list(HEBREW_YEARS_INFO.items()): rand_hdate.hdate = HebrewDate( year, rand_hdate.hdate.month, rand_hdate.hdate.day) assert rand_hdate.rosh_hashana_dow() == info[0]
def test_rosh_hashana_diaspora_edge_case(self): mydate = HDate(hebrew=False, diaspora=True) mydate.hdate = HebrewDate(5778, Months.Elul, 29) assert mydate.get_reading() == 52
def test_get_holidays_non_moving(self, rand_hdate, date, holiday): rand_hdate.hdate = HebrewDate(rand_hdate.hdate.year, date[1], date[0]) assert rand_hdate.holiday_name == holiday assert rand_hdate.is_holiday
def test_last_week_of_the_year(self): mydate = HDate() mydate.hdate = HebrewDate(5779, Months.Elul, 29) assert mydate.get_reading() == 52