Exemplo n.º 1
0
    def test_extend_od_for_non_day_interval(self, patch_shift_od):
        units = [DateUnit.YEAR, DateUnit.MONTH]
        units.extend(TimeUnit)
        interval = [FAKE.random_int(), FAKE.random_element(elements=units)]

        cd = ConvertibleDate(calendar=self.calendar_factory.build())
        cdt = ConvertibleDateTime(date=cd, time=self.time_factory.build())
        ordinal_decimal = FAKE.pyfloat()
        cdt.extend_od(ordinal_decimal, interval)
        patch_shift_od.assert_called_once_with(ordinal_decimal, [interval])
Exemplo n.º 2
0
    def test_extend_od_raises(self):
        units = list(DateUnit)
        units.extend(TimeUnit)
        interval = [FAKE.random_int(), FAKE.random_element(elements=units)]

        bad_factor = FAKE.random_int(min=-9999, max=0)
        cd = ConvertibleDate(calendar=self.calendar_factory.build())
        cdt = ConvertibleDateTime(date=cd, time=self.time_factory.build())
        ordinal_decimal = FAKE.pyfloat()
        with pytest.raises(ValueError):
            cdt.extend_od(ordinal_decimal, interval, bad_factor)
Exemplo n.º 3
0
    def test_extend_od_with_reverse(self, patch_shift_od):
        non_day_units = [DateUnit.YEAR, DateUnit.MONTH]
        non_day_units.extend(TimeUnit)
        non_day_unit = FAKE.random_element(elements=non_day_units)
        delta = FAKE.random_int(min=-9999)
        non_day_interval = [delta, non_day_unit]
        day_interval = [delta, DateUnit.DAY]

        cd = ConvertibleDate(calendar=self.calendar_factory.build())
        cdt = ConvertibleDateTime(date=cd, time=self.time_factory.build())
        od = FAKE.pyfloat()
        assert cdt.extend_od(od, day_interval, reverse=True) == od - delta
        patch_shift_od.assert_not_called()

        cdt.extend_od(od, non_day_interval, reverse=True)
        patch_shift_od.assert_called_with(od, [[-delta, non_day_unit]])
Exemplo n.º 4
0
    def test_extend_od_for_day_interval(self, patch_shift_od):
        delta = FAKE.random_int(min=-9999)
        interval = [delta, DateUnit.DAY]

        cd = ConvertibleDate(calendar=self.calendar_factory.build())
        cdt = ConvertibleDateTime(date=cd, time=self.time_factory.build())
        od = FAKE.pyfloat()
        assert cdt.extend_od(od, interval) == od + delta
        patch_shift_od.assert_not_called()