Example #1
0
 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
Example #2
0
 def test_get_next_yom_tov(self, current_date, holiday_date,
                           holiday_name, where, rand_hdate):
     if where == "BOTH" or where == "DIASPORA":
         hdate = HDate(gdate=datetime.date(*current_date), diaspora=True)
         next_yom_tov = hdate.upcoming_yom_tov
         assert next_yom_tov.gdate == datetime.date(*holiday_date)
     if where == "BOTH" or where == "ISRAEL":
         hdate = HDate(gdate=datetime.date(*current_date), diaspora=False)
         next_yom_tov = hdate.upcoming_yom_tov
         assert next_yom_tov.gdate == datetime.date(*holiday_date)
Example #3
0
 def test_daf_yomi(self):
     # Random test date
     myhdate = HDate(gdate=datetime.date(2014, 4, 28), hebrew=False)
     assert myhdate.daf_yomi == "Beitzah 29"
     # Beginning/end of cycle:
     myhdate = HDate(gdate=datetime.date(2020, 1, 4), hebrew=False)
     assert myhdate.daf_yomi == "Niddah 73"
     myhdate = HDate(gdate=datetime.date(2020, 1, 5), hebrew=False)
     assert myhdate.daf_yomi == "Berachos 2"
     myhdate = HDate(gdate=datetime.date(2020, 3, 7), hebrew=True)
     assert myhdate.daf_yomi == u"ברכות סד"
     myhdate = HDate(gdate=datetime.date(2020, 3, 8), hebrew=True)
     assert myhdate.daf_yomi == u"שבת ב"
Example #4
0
 def test_get_next_shabbat_or_yom_tov(self, current_date, diaspora,
                                      dates):
     hd = HDate(gdate=datetime.date(*current_date), diaspora=diaspora)
     assert (hd.upcoming_shabbat_or_yom_tov.first_day.gdate
             == datetime.date(*dates["start"]))
     assert (hd.upcoming_shabbat_or_yom_tov.last_day.gdate
             == datetime.date(*dates["end"]))
Example #5
0
 def test_readme_example_hebrew(self, capsys):
     test_date = date(2016, 4, 26)
     hdate = HDate(test_date, hebrew=True)
     print(hdate)
     captured = capsys.readouterr()
     assert (captured.out ==
             u"יום שלישי י\"ח בניסן ה' תשע\"ו ג' בעומר חול המועד פסח\n")
Example #6
0
 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 == ""
Example #7
0
 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]
Example #8
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]
Example #9
0
 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 == ""
Example #10
0
    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
Example #11
0
    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
Example #12
0
    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
Example #13
0
    async def async_update(self) -> None:
        """Update the state of the sensor."""
        now = dt_util.now()
        _LOGGER.debug("Now: %s Location: %r", now, self._location)

        today = now.date()
        event_date = get_astral_event_date(self.hass, SUN_EVENT_SUNSET, today)

        if event_date is None:
            _LOGGER.error("Can't get sunset event date for %s", today)
            return

        sunset = dt_util.as_local(event_date)

        _LOGGER.debug("Now: %s Sunset: %s", now, sunset)

        daytime_date = HDate(today,
                             diaspora=self._diaspora,
                             hebrew=self._hebrew)

        # The Jewish day starts after darkness (called "tzais") and finishes at
        # sunset ("shkia"). The time in between is a gray area (aka "Bein
        # Hashmashot" - literally: "in between the sun and the moon").

        # For some sensors, it is more interesting to consider the date to be
        # tomorrow based on sunset ("shkia"), for others based on "tzais".
        # Hence the following variables.
        after_tzais_date = after_shkia_date = daytime_date
        today_times = self.make_zmanim(today)

        if now > sunset:
            after_shkia_date = daytime_date.next_day

        if today_times.havdalah and now > today_times.havdalah:
            after_tzais_date = daytime_date.next_day

        self._attr_native_value = self.get_state(daytime_date,
                                                 after_shkia_date,
                                                 after_tzais_date)
        _LOGGER.debug("New value for %s: %s", self.entity_description.key,
                      self._attr_native_value)
Example #14
0
 def test_get_upcoming_parasha(self):
     """Check that the upcoming parasha is correct."""
     test_date = datetime(2018, 11, 2)
     assert HDate(test_date).parasha == u"חיי שרה"
     assert HDate(test_date, hebrew=False).parasha == "Chayei Sara"
Example #15
0
 def test_get_hebrew_date(self):
     """Print the hebrew date."""
     test_date = datetime(2018, 11, 2)
     assert HDate(test_date).hebrew_date == u'כ"ד מרחשוון ה\' תשע"ט'
     assert HDate(test_date,
                  hebrew=False).hebrew_date == "24 Marcheshvan 5779"
Example #16
0
 def test_last_week_of_the_year(self):
     mydate = HDate()
     mydate.hdate = HebrewDate(5779, Months.Elul, 29)
     assert mydate.get_reading() == 52
Example #17
0
 def test_readme_example_english(self, capsys):
     test_date = date(2016, 4, 18)
     hdate = HDate(test_date, hebrew=False)
     print(hdate)
     captured = capsys.readouterr()
     assert captured.out == "Monday 10 Nisan 5776\n"
Example #18
0
 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)
Example #19
0
 def test_random_hdate(self, execution_number, rand_hdate):
     _hdate = HDate()
     _hdate.hdate = rand_hdate.hdate
     assert _hdate._jdn == rand_hdate._jdn
     assert _hdate.hdate == rand_hdate.hdate
     assert _hdate.gdate == rand_hdate.gdate
Example #20
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
Example #21
0
 def test_get_upcoming_parasha_vezot_habracha(self):
     """Check that the upcoming parasha is correct for vezot habracha."""
     test_date = datetime(2018, 9, 30)
     assert HDate(test_date).parasha == u"וזאת הברכה"
     assert HDate(test_date, hebrew=False).parasha == "Vezot Habracha"
Example #22
0
 def test_get_holiday_description(self):
     """Check that the holiday description is correct."""
     test_date = datetime(2018, 12, 3)
     assert HDate(test_date).holiday_description == u"חנוכה"
     assert HDate(test_date, hebrew=False).holiday_description == "Chanukah"
Example #23
0
 def default_values(self):
     return HDate()