Example #1
0
 def test_mixed_truth_restricted_type(self) -> None:
     # join_types against differently restricted truthiness types drops restrictions.
     true_any = true_only(AnyType(TypeOfAny.special_form))
     false_o = false_only(self.fx.o)
     j = join_types(true_any, false_o)
     assert_true(j.can_be_true)
     assert_true(j.can_be_false)
Example #2
0
 def test_mixed_truth_restricted_type(self):
     # join_types against differently restricted truthiness types drops restrictions.
     true_any = true_only(AnyType())
     false_o = false_only(self.fx.o)
     j = join_types(true_any, false_o)
     assert_true(j.can_be_true)
     assert_true(j.can_be_false)
Example #3
0
 def test_mixed_truth_restricted_type_simple(self) -> None:
     # join_simple against differently restricted truthiness types drops restrictions.
     true_a = true_only(self.fx.a)
     false_o = false_only(self.fx.o)
     j = join_simple(self.fx.o, true_a, false_o)
     assert_true(j.can_be_true)
     assert_true(j.can_be_false)
Example #4
0
 def test_mixed_truth_restricted_type_simple(self):
     # join_simple against differently restricted truthiness types drops restrictions.
     true_a = true_only(self.fx.a)
     false_o = false_only(self.fx.o)
     j = join_simple(self.fx.o, true_a, false_o)
     assert_true(j.can_be_true)
     assert_true(j.can_be_false)
Example #5
0
 def test_false_only_of_instance(self) -> None:
     fo = false_only(self.fx.a)
     assert_equal(str(fo), "A")
     assert_false(fo.can_be_true)
     assert_true(fo.can_be_false)
     assert_type(Instance, fo)
     # The original class still can be true
     assert_true(self.fx.a.can_be_true)
Example #6
0
    def test_is_proper_subtype_invariance(self):
        fx = self.fx

        assert_true(is_proper_subtype(fx.gsab, fx.gb))
        assert_false(is_proper_subtype(fx.gsab, fx.ga))
        assert_false(is_proper_subtype(fx.gsaa, fx.gb))
        assert_false(is_proper_subtype(fx.gb, fx.ga))
        assert_false(is_proper_subtype(fx.ga, fx.gb))
Example #7
0
 def test_true_only_of_instance(self) -> None:
     to = true_only(self.fx.a)
     assert_equal(str(to), "A")
     assert_true(to.can_be_true)
     assert_false(to.can_be_false)
     assert_type(Instance, to)
     # The original class still can be false
     assert_true(self.fx.a.can_be_false)
Example #8
0
 def test_true_only_of_instance(self):
     to = true_only(self.fx.a)
     assert_equal(str(to), "A")
     assert_true(to.can_be_true)
     assert_false(to.can_be_false)
     assert_type(Instance, to)
     # The original class still can be false
     assert_true(self.fx.a.can_be_false)
Example #9
0
 def test_false_only_of_instance(self):
     fo = false_only(self.fx.a)
     assert_equal(str(fo), "A")
     assert_false(fo.can_be_true)
     assert_true(fo.can_be_false)
     assert_type(Instance, fo)
     # The original class still can be true
     assert_true(self.fx.a.can_be_true)
Example #10
0
    def test_is_proper_subtype_invariance(self):
        fx = self.fx

        assert_true(is_proper_subtype(fx.gsab, fx.gb))
        assert_false(is_proper_subtype(fx.gsab, fx.ga))
        assert_false(is_proper_subtype(fx.gsaa, fx.gb))
        assert_false(is_proper_subtype(fx.gb, fx.ga))
        assert_false(is_proper_subtype(fx.ga, fx.gb))
Example #11
0
 def assert_simple_meet(self, s: Type, t: Type, meet: Type) -> None:
     result = meet_types(s, t)
     actual = str(result)
     expected = str(meet)
     assert_equal(actual, expected,
                  'meet({}, {}) == {{}} ({{}} expected)'.format(s, t))
     assert_true(is_subtype(result, s),
                 '{} not subtype of {}'.format(result, s))
     assert_true(is_subtype(result, t),
                 '{} not subtype of {}'.format(result, t))
Example #12
0
 def test_true_only_of_union(self):
     tup_type = self.tuple(AnyType())
     # Union of something that is unknown, something that is always true, something
     # that is always false
     union_type = UnionType([self.fx.a, tup_type, self.tuple()])
     to = true_only(union_type)
     assert_equal(len(to.items), 2)
     assert_true(to.items[0].can_be_true)
     assert_false(to.items[0].can_be_false)
     assert_true(to.items[1] is tup_type)
Example #13
0
 def assert_simple_join(self, s: Type, t: Type, join: Type) -> None:
     result = join_types(s, t)
     actual = str(result)
     expected = str(join)
     assert_equal(actual, expected,
                  'join({}, {}) == {{}} ({{}} expected)'.format(s, t))
     assert_true(is_subtype(s, result),
                 '{} not subtype of {}'.format(s, result))
     assert_true(is_subtype(t, result),
                 '{} not subtype of {}'.format(t, result))
Example #14
0
 def test_simple_type_objects(self):
     t1 = self.type_callable(self.fx.a, self.fx.a)
     t2 = self.type_callable(self.fx.b, self.fx.b)
     
     self.assert_join(t1, t1, t1)
     assert_true(join_types(t1, t1, self.fx.basic).is_type_obj())
     
     self.assert_join(t1, t2, self.fx.std_type)
     self.assert_join(t1, self.fx.std_type, self.fx.std_type)
     self.assert_join(self.fx.std_type, self.fx.std_type, self.fx.std_type)
Example #15
0
    def test_simple_type_objects(self):
        t1 = self.type_callable(self.fx.a, self.fx.a)
        t2 = self.type_callable(self.fx.b, self.fx.b)

        self.assert_join(t1, t1, t1)
        assert_true(join_types(t1, t1).is_type_obj())

        self.assert_join(t1, t2, self.fx.type_type)
        self.assert_join(t1, self.fx.type_type, self.fx.type_type)
        self.assert_join(self.fx.type_type, self.fx.type_type,
                         self.fx.type_type)
Example #16
0
 def assert_simple_join(self, s, t, join):
     result = join_types(s, t)
     actual = str(result)
     expected = str(join)
     assert_equal(actual, expected,
                  'join({}, {}) == {{}} ({{}} expected)'.format(s, t))
     if not isinstance(s, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(s, result),
                     '{} not subtype of {}'.format(s, result))
     if not isinstance(t, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(t, result),
                     '{} not subtype of {}'.format(t, result))
Example #17
0
 def assert_simple_meet(self, s, t, meet):
     result = meet_types(s, t)
     actual = str(result)
     expected = str(meet)
     assert_equal(actual, expected,
                  'meet({}, {}) == {{}} ({{}} expected)'.format(s, t))
     if not isinstance(s, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(result, s),
                     '{} not subtype of {}'.format(result, s))
     if not isinstance(t, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(result, t),
                     '{} not subtype of {}'.format(result, t))
Example #18
0
 def assert_simple_meet(self, s, t, meet):
     result = meet_types(s, t)
     actual = str(result)
     expected = str(meet)
     assert_equal(actual, expected,
                  'meet({}, {}) == {{}} ({{}} expected)'.format(s, t))
     if not isinstance(s, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(result, s),
                     '{} not subtype of {}'.format(result, s))
     if not isinstance(t, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(result, t),
                     '{} not subtype of {}'.format(result, t))
Example #19
0
 def assert_simple_join(self, s, t, join):
     result = join_types(s, t)
     actual = str(result)
     expected = str(join)
     assert_equal(actual, expected,
                  'join({}, {}) == {{}} ({{}} expected)'.format(s, t))
     if not isinstance(s, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(s, result),
                     '{} not subtype of {}'.format(s, result))
     if not isinstance(t, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(t, result),
                     '{} not subtype of {}'.format(t, result))
Example #20
0
 def test_false_only_of_union(self) -> None:
     tup_type = self.tuple()
     # Union of something that is unknown, something that is always true, something
     # that is always false
     union_type = UnionType([self.fx.a, self.tuple(AnyType()), tup_type])
     assert_equal(len(union_type.items), 3)
     fo = false_only(union_type)
     assert isinstance(fo, UnionType)
     assert_equal(len(fo.items), 2)
     assert_false(fo.items[0].can_be_true)
     assert_true(fo.items[0].can_be_false)
     assert_true(fo.items[1] is tup_type)
Example #21
0
 def test_false_only_of_union(self) -> None:
     tup_type = self.tuple()
     # Union of something that is unknown, something that is always true, something
     # that is always false
     union_type = UnionType([self.fx.a, self.tuple(AnyType()), tup_type])
     assert_equal(len(union_type.items), 3)
     fo = false_only(union_type)
     assert isinstance(fo, UnionType)
     assert_equal(len(fo.items), 2)
     assert_false(fo.items[0].can_be_true)
     assert_true(fo.items[0].can_be_false)
     assert_true(fo.items[1] is tup_type)
Example #22
0
    def test_simple_type_objects(self) -> None:
        t1 = self.type_callable(self.fx.a, self.fx.a)
        t2 = self.type_callable(self.fx.b, self.fx.b)

        self.assert_join(t1, t1, t1)
        j = join_types(t1, t1)
        assert isinstance(j, CallableType)
        assert_true(j.is_type_obj())

        self.assert_join(t1, t2, self.fx.type_type)
        self.assert_join(t1, self.fx.type_type, self.fx.type_type)
        self.assert_join(self.fx.type_type, self.fx.type_type,
                         self.fx.type_type)
Example #23
0
    def test_is_more_precise(self):
        fx = self.fx
        assert_true(is_more_precise(fx.b, fx.a))
        assert_true(is_more_precise(fx.b, fx.b))
        assert_true(is_more_precise(fx.b, fx.b))
        assert_true(is_more_precise(fx.b, fx.anyt))
        assert_true(is_more_precise(self.tuple(fx.b, fx.a),
                                    self.tuple(fx.b, fx.a)))

        assert_false(is_more_precise(fx.a, fx.b))
        assert_false(is_more_precise(fx.anyt, fx.b))
        assert_false(is_more_precise(self.tuple(fx.b, fx.b),
                                     self.tuple(fx.b, fx.a)))
Example #24
0
    def test_simple_type_objects(self) -> None:
        t1 = self.type_callable(self.fx.a, self.fx.a)
        t2 = self.type_callable(self.fx.b, self.fx.b)

        self.assert_join(t1, t1, t1)
        j = join_types(t1, t1)
        assert isinstance(j, CallableType)
        assert_true(j.is_type_obj())

        self.assert_join(t1, t2, self.fx.type_type)
        self.assert_join(t1, self.fx.type_type, self.fx.type_type)
        self.assert_join(self.fx.type_type, self.fx.type_type,
                         self.fx.type_type)
Example #25
0
    def test_is_more_precise(self):
        fx = self.fx
        assert_true(is_more_precise(fx.b, fx.a))
        assert_true(is_more_precise(fx.b, fx.b))
        assert_true(is_more_precise(fx.b, fx.b))
        assert_true(is_more_precise(fx.b, fx.anyt))
        assert_true(
            is_more_precise(self.tuple(fx.b, fx.a), self.tuple(fx.b, fx.a)))

        assert_false(is_more_precise(fx.a, fx.b))
        assert_false(is_more_precise(fx.anyt, fx.b))
        assert_false(
            is_more_precise(self.tuple(fx.b, fx.b), self.tuple(fx.b, fx.a)))
Example #26
0
 def test_is_in_module_collection(self):
     assert_true(moduleinfo.is_in_module_collection({'foo'}, 'foo'))
     assert_true(moduleinfo.is_in_module_collection({'foo'}, 'foo.bar'))
     assert_false(moduleinfo.is_in_module_collection({'foo'}, 'fo'))
     assert_true(moduleinfo.is_in_module_collection({'foo.bar'}, 'foo.bar'))
     assert_true(moduleinfo.is_in_module_collection({'foo.bar'}, 'foo.bar.zar'))
     assert_false(moduleinfo.is_in_module_collection({'foo.bar'}, 'foo'))
Example #27
0
 def test_is_in_module_collection(self):
     assert_true(moduleinfo.is_in_module_collection({'foo'}, 'foo'))
     assert_true(moduleinfo.is_in_module_collection({'foo'}, 'foo.bar'))
     assert_false(moduleinfo.is_in_module_collection({'foo'}, 'fo'))
     assert_true(moduleinfo.is_in_module_collection({'foo.bar'}, 'foo.bar'))
     assert_true(
         moduleinfo.is_in_module_collection({'foo.bar'}, 'foo.bar.zar'))
     assert_false(moduleinfo.is_in_module_collection({'foo.bar'}, 'foo'))
Example #28
0
    def test_is_proper_subtype_covariance(self) -> None:
        fx_co = self.fx_co

        assert_true(is_proper_subtype(fx_co.gsab, fx_co.gb))
        assert_true(is_proper_subtype(fx_co.gsab, fx_co.ga))
        assert_false(is_proper_subtype(fx_co.gsaa, fx_co.gb))
        assert_true(is_proper_subtype(fx_co.gb, fx_co.ga))
        assert_false(is_proper_subtype(fx_co.ga, fx_co.gb))
Example #29
0
    def test_is_proper_subtype_covariance(self) -> None:
        fx_co = self.fx_co

        assert_true(is_proper_subtype(fx_co.gsab, fx_co.gb))
        assert_true(is_proper_subtype(fx_co.gsab, fx_co.ga))
        assert_false(is_proper_subtype(fx_co.gsaa, fx_co.gb))
        assert_true(is_proper_subtype(fx_co.gb, fx_co.ga))
        assert_false(is_proper_subtype(fx_co.ga, fx_co.gb))
Example #30
0
    def test_is_proper_subtype_contravariance(self):
        fx_contra = self.fx_contra

        assert_true(is_proper_subtype(fx_contra.gsab, fx_contra.gb))
        assert_false(is_proper_subtype(fx_contra.gsab, fx_contra.ga))
        assert_true(is_proper_subtype(fx_contra.gsaa, fx_contra.gb))
        assert_false(is_proper_subtype(fx_contra.gb, fx_contra.ga))
        assert_true(is_proper_subtype(fx_contra.ga, fx_contra.gb))
Example #31
0
    def test_is_proper_subtype_contravariance(self):
        fx_contra = self.fx_contra

        assert_true(is_proper_subtype(fx_contra.gsab, fx_contra.gb))
        assert_false(is_proper_subtype(fx_contra.gsab, fx_contra.ga))
        assert_true(is_proper_subtype(fx_contra.gsaa, fx_contra.gb))
        assert_false(is_proper_subtype(fx_contra.gb, fx_contra.ga))
        assert_true(is_proper_subtype(fx_contra.ga, fx_contra.gb))
Example #32
0
 def test_true_only_of_true_type_is_idempotent(self):
     always_true = self.tuple(AnyType())
     to = true_only(always_true)
     assert_true(always_true is to)
Example #33
0
 def test_false_only_of_false_type_is_idempotent(self):
     always_false = NoneTyp()
     fo = false_only(always_false)
     assert_true(always_false is fo)
Example #34
0
 def assert_subtype(self, s, t):
     assert_true(is_subtype(s, t), '{} not subtype of {}'.format(s, t))
Example #35
0
 def test_true_only_of_true_type_is_idempotent(self) -> None:
     always_true = self.tuple(AnyType(TypeOfAny.special_form))
     to = true_only(always_true)
     assert_true(always_true is to)
Example #36
0
 def test_empty_tuple_always_false(self):
     tuple_type = self.tuple()
     assert_true(tuple_type.can_be_false)
     assert_false(tuple_type.can_be_true)
Example #37
0
 def test_union_can_be_true_if_any_true(self):
     union_type = UnionType([self.fx.a, self.tuple()])
     assert_true(union_type.can_be_true)
Example #38
0
 def assert_not_subtype(self, s, t):
     assert_true(not is_subtype(s, t), '{} subtype of {}'.format(s, t))
Example #39
0
 def assert_subtype(self, s, t):
     assert_true(is_subtype(s, t), '{} not subtype of {}'.format(s, t))
Example #40
0
 def test_nonempty_tuple_always_true(self) -> None:
     tuple_type = self.tuple(AnyType(), AnyType())
     assert_true(tuple_type.can_be_true)
     assert_false(tuple_type.can_be_false)
Example #41
0
    def test_is_proper_subtype(self) -> None:
        fx = self.fx

        assert_true(is_proper_subtype(fx.a, fx.a))
        assert_true(is_proper_subtype(fx.b, fx.a))
        assert_true(is_proper_subtype(fx.b, fx.o))
        assert_true(is_proper_subtype(fx.b, fx.o))

        assert_false(is_proper_subtype(fx.a, fx.b))
        assert_false(is_proper_subtype(fx.o, fx.b))

        assert_true(is_proper_subtype(fx.anyt, fx.anyt))
        assert_false(is_proper_subtype(fx.a, fx.anyt))
        assert_false(is_proper_subtype(fx.anyt, fx.a))

        assert_true(is_proper_subtype(fx.ga, fx.ga))
        assert_true(is_proper_subtype(fx.gdyn, fx.gdyn))
        assert_false(is_proper_subtype(fx.ga, fx.gdyn))
        assert_false(is_proper_subtype(fx.gdyn, fx.ga))

        assert_true(is_proper_subtype(fx.t, fx.t))
        assert_false(is_proper_subtype(fx.t, fx.s))

        assert_true(is_proper_subtype(fx.a, UnionType([fx.a, fx.b])))
        assert_true(
            is_proper_subtype(UnionType([fx.a, fx.b]),
                              UnionType([fx.a, fx.b, fx.c])))
        assert_false(
            is_proper_subtype(UnionType([fx.a, fx.b]), UnionType([fx.b,
                                                                  fx.c])))
Example #42
0
 def test_empty_tuple_always_false(self) -> None:
     tuple_type = self.tuple()
     assert_true(tuple_type.can_be_false)
     assert_false(tuple_type.can_be_true)
Example #43
0
 def test_nonempty_tuple_always_true(self) -> None:
     tuple_type = self.tuple(AnyType(TypeOfAny.special_form),
                             AnyType(TypeOfAny.special_form))
     assert_true(tuple_type.can_be_true)
     assert_false(tuple_type.can_be_false)
Example #44
0
 def test_union_can_be_true_if_any_true(self) -> None:
     union_type = UnionType([self.fx.a, self.tuple()])
     assert_true(union_type.can_be_true)
Example #45
0
 def test_union_can_be_false_if_any_false(self):
     union_type = UnionType([self.fx.a, self.tuple()])
     assert_true(union_type.can_be_false)
Example #46
0
 def assert_not_subtype(self, s: Type, t: Type) -> None:
     assert_true(not is_subtype(s, t), '{} subtype of {}'.format(s, t))
Example #47
0
 def assert_not_subtype(self, s: Type, t: Type) -> None:
     assert_true(not is_subtype(s, t), '{} subtype of {}'.format(s, t))
Example #48
0
    def test_is_proper_subtype(self):
        fx = self.fx

        assert_true(is_proper_subtype(fx.a, fx.a))
        assert_true(is_proper_subtype(fx.b, fx.a))
        assert_true(is_proper_subtype(fx.b, fx.o))
        assert_true(is_proper_subtype(fx.b, fx.o))

        assert_false(is_proper_subtype(fx.a, fx.b))
        assert_false(is_proper_subtype(fx.o, fx.b))

        assert_true(is_proper_subtype(fx.anyt, fx.anyt))
        assert_false(is_proper_subtype(fx.a, fx.anyt))
        assert_false(is_proper_subtype(fx.anyt, fx.a))

        assert_true(is_proper_subtype(fx.ga, fx.ga))
        assert_true(is_proper_subtype(fx.gdyn, fx.gdyn))
        assert_false(is_proper_subtype(fx.ga, fx.gdyn))
        assert_false(is_proper_subtype(fx.gdyn, fx.ga))

        assert_true(is_proper_subtype(fx.t, fx.t))
        assert_false(is_proper_subtype(fx.t, fx.s))
Example #49
0
 def assert_not_subtype(self, s, t):
     assert_true(not is_subtype(s, t), '{} subtype of {}'.format(s, t))
Example #50
0
 def test_nonempty_tuple_always_true(self):
     tuple_type = self.tuple(AnyType(), AnyType())
     assert_true(tuple_type.can_be_true)
     assert_false(tuple_type.can_be_false)
Example #51
0
    def test_is_proper_subtype(self):
        fx = self.fx

        assert_true(is_proper_subtype(fx.a, fx.a))
        assert_true(is_proper_subtype(fx.b, fx.a))
        assert_true(is_proper_subtype(fx.b, fx.o))
        assert_true(is_proper_subtype(fx.b, fx.o))

        assert_false(is_proper_subtype(fx.a, fx.b))
        assert_false(is_proper_subtype(fx.o, fx.b))

        assert_true(is_proper_subtype(fx.anyt, fx.anyt))
        assert_false(is_proper_subtype(fx.a, fx.anyt))
        assert_false(is_proper_subtype(fx.anyt, fx.a))

        assert_true(is_proper_subtype(fx.ga, fx.ga))
        assert_true(is_proper_subtype(fx.gdyn, fx.gdyn))
        assert_false(is_proper_subtype(fx.ga, fx.gdyn))
        assert_false(is_proper_subtype(fx.gdyn, fx.ga))

        assert_true(is_proper_subtype(fx.t, fx.t))
        assert_false(is_proper_subtype(fx.t, fx.s))
Example #52
0
 def test_union_can_be_false_if_any_false(self) -> None:
     union_type = UnionType([self.fx.a, self.tuple()])
     assert_true(union_type.can_be_false)
Example #53
0
 def test_false_only_of_false_type_is_idempotent(self) -> None:
     always_false = NoneTyp()
     fo = false_only(always_false)
     assert_true(always_false is fo)