Exemplo n.º 1
0
class TestJulianCalendar(CalendarTest):
    def setUp(self):
        self.calendar = JulianCalendar()
        self.setUpDateEquality()

    def test_display_string(self):
        """ The display string for a date gives the correct date and specifies the calendar. """
        d = self.calendar.date(1415, 10, 25)
        self.assertEqual(str(d), "25th October 1415 (Julian Calendar)")

    @given(datetimes(timezones=[]))
    @example(datetime(2100, 3, 1, 0, 0, 0))
    @example(datetime(4500, 4, 1, 0, 0, 0))
    @example(datetime(8200, 3, 1, 0, 0, 0))
    def test_make_julian_date_directly_and_via_year_month_day(self, dt):
        d = dt.date()
        julian_date_from_date = self.calendar.from_date(d)
        julian_representation = self.calendar.julian_representation(d)
        year, month, day = julian_representation
        julian_date_from_representation = self.calendar.date(year, month, day)
        self.calendar.bless(julian_date_from_representation)
        self.assertEqual(julian_date_from_date, julian_date_from_representation)

    def test_julian_number(self):
        d = self.calendar.date(1415, 10, 25)
        self.assertEqual(self.calendar.julian_day_number(d), 2238184)

    def test_julian_representation(self):
        d = date(8200, 3, 1)
        self.assertEqual(self.calendar.julian_representation(d), (8200, 1, 1))

    def test_making_a_tricky_date_correctly(self):
        julian_date = self.calendar.date(8200, 1, 1)
        self.assertEqual(julian_date.to_date(), date(8200, 3, 1))

    @given(datetimes(timezones=[]))
    @example(datetime(8200, 3, 1, 0, 0, 0))
    @example(datetime(8200, 2, 28, 0, 0, 0))
    @example(datetime(8199, 12, 31, 0, 0, 0))
    def test_julian_representation_round_trips_with_conversion(self, dt):
        d = dt.date()
        y, m, day = self.calendar.julian_representation(d)
        julian_date = self.calendar.date(y, m, day)
        self.assertEqual(julian_date.to_date(), d)