def test_next_ast_ymd(self, *mocks): mock_next_day = mocks[0] mock_next_month = mocks[1] mock_next_ast_year = mocks[2] mock_next_era = mocks[3] calendar = self.calendar_factory.build() year = month = day = FAKE.random_int() ymd = year, month, day positive_frequency = FAKE.random_int() negative_frequency = FAKE.random_int(min=-20, max=-1) forward = FAKE.pybool() cd = ConvertibleDate(calendar=calendar) cd.next_ast_ymd(ymd, [positive_frequency, DateUnit.ERA], forward) mock_next_era.assert_called_with(year, positive_frequency, forward) cd.next_ast_ymd(ymd, [negative_frequency, DateUnit.ERA], forward) mock_next_era.assert_called_with(year, negative_frequency, forward) cd.next_ast_ymd(ymd, [positive_frequency, DateUnit.YEAR], forward) mock_next_ast_year.assert_called_with(year, positive_frequency, forward) cd.next_ast_ymd(ymd, [negative_frequency, DateUnit.YEAR], forward) mock_next_ast_year.assert_called_with(year, negative_frequency, forward) cd.next_ast_ymd(ymd, [positive_frequency, DateUnit.MONTH], forward) mock_next_month.assert_called_with(year, month, positive_frequency, forward) cd.next_ast_ymd(ymd, [negative_frequency, DateUnit.MONTH], forward) mock_next_month.assert_called_with(year, month, negative_frequency, forward) cd.next_ast_ymd(ymd, [positive_frequency, DateUnit.DAY], forward) mock_next_day.assert_called_with(ymd, positive_frequency, forward) cd.next_ast_ymd(ymd, [negative_frequency, DateUnit.DAY], forward) mock_next_day.assert_called_with(ymd, negative_frequency, forward) with pytest.raises(ValueError): cd.next_ast_ymd(ymd, FAKE.words(nb=2))
def test_next_od_for_time_unit(self, *patches): patch_set_hms = patches[0] patch_next_hms = patches[1] patch_od_to_hms = patches[2] fake_hms1 = FAKE.random_int(), FAKE.random_int(), FAKE.random_int() fake_hms2 = FAKE.random_int(), FAKE.random_int(), FAKE.random_int() fake_od = FAKE.random_int() day_delta = FAKE.random_int() interval = [FAKE.random_int(), FAKE.random_element(elements=TimeUnit)] forward = FAKE.pybool() patch_od_to_hms.return_value = fake_hms1 patch_next_hms.return_value = fake_hms2, day_delta patch_set_hms.return_value = fake_od cd = ConvertibleDate(calendar=self.calendar_factory.build()) cdt = ConvertibleDateTime(date=cd, time=self.time_factory.build()) assert cdt.next_od(fake_od, interval, forward) == fake_od patch_od_to_hms.assert_called_once_with(fake_od) patch_next_hms.assert_called_once_with(fake_hms1, interval, forward) patch_set_hms.assert_called_once_with(fake_od, fake_hms2, day_delta)
def test_next_od_for_date_unit(self, *patches): patch_ast_ymd_to_od = patches[0] patch_next_ast_ymd = patches[1] patch_od_to_ast_ymd = patches[2] od1 = FAKE.pyfloat() od2 = FAKE.pyfloat() ast_ymd1 = FAKE.random_int(), FAKE.random_int(), FAKE.random_int() ast_ymd2 = FAKE.random_int(), FAKE.random_int(), FAKE.random_int() interval = [FAKE.random_int(), FAKE.random_element(elements=DateUnit)] forward = FAKE.pybool() patch_od_to_ast_ymd.return_value = ast_ymd1 patch_next_ast_ymd.return_value = ast_ymd2 patch_ast_ymd_to_od.return_value = od2 cd = ConvertibleDate(calendar=self.calendar_factory.build()) cdt = ConvertibleDateTime(date=cd, time=self.time_factory.build()) assert cdt.next_od(od1, interval, forward) == od2 patch_od_to_ast_ymd.assert_called_once_with(od1) patch_next_ast_ymd.assert_called_once_with(ast_ymd1, interval, forward) patch_ast_ymd_to_od.assert_called_once_with(ast_ymd2)
def test_next_ast_ymd_fo_invalid_ymd(self, _): calendar = self.calendar_factory.build() cd = ConvertibleDate(calendar=calendar) with pytest.raises(ValueError): cd.next_ast_ymd(FAKE.pytuple(), FAKE.pylist(), FAKE.pybool())