Exemplo n.º 1
0
 def test_shift_ast_ymd_with_diff_months_in_leap_and_common_years(self):
     days_in_common_year_months = FAKE.random_choices(
         elements=[x for x in range(200)], length=11)
     days_in_leap_year_months = FAKE.random_choices(
         elements=[x for x in range(200)], length=12)
     days_in_common_year_months.append(30)
     days_in_leap_year_months.append(31)
     calendar = self.calendar_factory.build(
         common_year_month_names=FAKE.words(nb=12),
         days_in_common_year_months=days_in_common_year_months,
         leap_year_month_names=FAKE.words(nb=13),
         days_in_leap_year_months=days_in_leap_year_months,
         leap_year_cycles=[4],
         leap_year_cycle_start=1,
         leap_year_cycle_ordinals=[4],
         special_common_years=(),
         special_leap_years=(),
         leap_year_offset=0,
     )
     cd = ConvertibleDate(calendar=calendar)
     plus_one_year = [[1, DateUnit.YEAR]]
     sub_one_year = [[-1, DateUnit.YEAR]]
     with self.session:
         self.session.add(calendar)
         self.session.flush()
         assert cd.shift_ast_ymd((4, 13, 1), plus_one_year) == (5, 12, 1)
         assert cd.shift_ast_ymd((8, 13, 1), sub_one_year) == (7, 12, 1)
         assert cd.shift_ast_ymd((0, 13, 31), plus_one_year) == (1, 12, 30)
         assert cd.shift_ast_ymd((-4, 13, 31), sub_one_year) == (-5, 12, 30)
Exemplo n.º 2
0
    def test_days_in_leap_year_raises(self):
        num_common_months = FAKE.random_int(min=11, max=20)
        num_leap_months = FAKE.random_int(min=1, max=10)

        common_month_names = FAKE.words(nb=num_common_months)
        days_in_common_year_months = FAKE.random_choices(
            elements=list(range(11, 20)),
            length=num_common_months,
        )

        leap_month_names = FAKE.words(nb=num_leap_months)
        days_in_leap_year_months = FAKE.random_choices(
            elements=list(range(1, 10)),
            length=num_leap_months,
        )
        too_long_common_year_cal = self.calendar_factory.build(
            common_year_month_names=common_month_names,
            days_in_common_year_months=days_in_common_year_months,
            leap_year_month_names=leap_month_names,
            days_in_leap_year_months=days_in_leap_year_months,
        )
        with pytest.raises(AssertionError):
            _ = too_long_common_year_cal.days_in_leap_year