Пример #1
0
    def test_110_naivety_is_preserved(self):
        class NaivetyCheck:
            def __init__(self, hour100, minute100, to_utc=None):
                self.hour100 = hour100
                self.minute100 = minute100
                self.to_utc = to_utc

            def to_time_pair(self):
                return Fraction(self.hour100 * 100 + self.minute100,
                                10000), None

            @classmethod
            def from_time_pair(cls, day_frac, to_utc=None):
                minutes_tot = day_frac * 10000
                hour100 = int(minutes_tot / 100)
                return cls(hour100, minutes_tot - hour100 * 100)

        Time.register_new_time("test_1", NaivetyCheck)

        t1 = Time("17/24")
        assert t1.test_1.to_utc is None

        t2 = Time("17/24", to_utc=0)
        assert t2.test_1.to_utc is not None

        t3 = Time.test_1(11, 12)
        assert t3.to_utc is None

        t4 = Time.test_1(11, 12, to_utc=0)
        assert t4.to_utc is not None
Пример #2
0
    def test_040_registered_attribute_simple_class(self, class_Time_resource):
        Time.register_new_time("test_1", ExampleTestTimeRepresentation)

        # Time attribute type and metaclass are correct
        assert Time.test_1.__name__ == "ExampleTestTimeRepresentationInTime"
        assert type(Time.test_1).__name__ == "ModifiedClass"
        assert issubclass(Time.test_1, ExampleTestTimeRepresentation)

        # constructed Time type and value are is correct
        t1a = Time.test_1(10, 8)
        assert type(t1a) == Time
        assert t1a.day_frac == Fraction(63, 625)

        # new attribute on Time instance, type and value are correct
        t1b = Time("963/1250")
        assert isinstance(t1b.test_1, ExampleTestTimeRepresentation)
        assert type(
            t1b.test_1).__name__ == "ExampleTestTimeRepresentationInTime"
        assert type(t1b.test_1.__class__).__name__ == "ModifiedClass"
        assert t1b.test_1.hour100 == 77
        assert t1b.test_1.minute100 == 4

        # new attribute on Time instance build by another calendar, type and value are correct
        t1c = Time.western(10, 35, 15)
        assert isinstance(t1c.test_1, ExampleTestTimeRepresentation)
        assert type(
            t1c.test_1).__name__ == "ExampleTestTimeRepresentationInTime"
        assert type(t1c.test_1.__class__).__name__ == "ModifiedClass"
        assert t1c.test_1.hour100 == 44
        assert t1c.test_1.minute100 == Fraction("275/24")
Пример #3
0
    def test_040_registered_attribute_simple_class(self, class_Time_resource):
        Time.register_new_time('test_1', ExampleTestTimeRepresentation)

        # Time attribute type and metaclass are correct
        assert Time.test_1.__name__ == 'ExampleTestTimeRepresentationInTime'
        assert type(Time.test_1).__name__ == 'ModifiedClass'
        assert issubclass(Time.test_1, ExampleTestTimeRepresentation)

        # constructed Time type and value are is correct
        t1a = Time.test_1(10, 8)
        assert type(t1a) == Time
        assert t1a.day_frac == Fraction(63, 625)

        # new attribute on Time instance, type and value are correct
        t1b = Time("963/1250")
        assert isinstance(t1b.test_1, ExampleTestTimeRepresentation)
        assert type(t1b.test_1).__name__ == 'ExampleTestTimeRepresentationInTime'
        assert type(t1b.test_1.__class__).__name__ == 'ModifiedClass'
        assert t1b.test_1.hour100 == 77
        assert t1b.test_1.minute100 == 4

        # new attribute on Time instance build by another calendar, type and value are correct
        t1c = Time.western(10, 35, 15)
        assert isinstance(t1c.test_1, ExampleTestTimeRepresentation)
        assert type(t1c.test_1).__name__ == 'ExampleTestTimeRepresentationInTime'
        assert type(t1c.test_1.__class__).__name__ == 'ModifiedClass'
        assert t1c.test_1.hour100 == 44
        assert t1c.test_1.minute100 == Fraction("275/24")