Ejemplo n.º 1
0
    def test_create_union_type_with_vars(self):
        union = UnionType.add(int, str)
        compare_types(union, [int, str])

        union2 = UnionType(union, list)
        compare_types(union, [int, str])
        compare_types(union2, [int, str, list])

        self.assertFalse(union == union2)

        clone = UnionType.add(int, str)
        self.assertTrue(union == clone)
Ejemplo n.º 2
0
    def test_create_union_type_with_classes(self):
        class Foo:
            pass

        union = UnionType.add(Foo, AssertionError)
        compare_types(union, [Foo, AssertionError])

        union2 = UnionType(union, object)
        compare_types(union2, [Foo, AssertionError, object])

        clone = UnionType.add(Foo, AssertionError)
        self.assertFalse(union == union2)
        self.assertTrue(union == clone)
Ejemplo n.º 3
0
    def test_create_union_type_with_funcs(self):
        def foo():
            pass

        union = UnionType.add(foo, range)
        compare_types(union, [foo, range])

        union2 = UnionType(union, getattr)
        compare_types(union, [foo, range])
        compare_types(union2, [foo, range, getattr])

        self.assertFalse(union == union2)

        clone = UnionType.add(foo, range)
        self.assertTrue(union == clone)
Ejemplo n.º 4
0
    def test_create_union_type_with_instances(self):
        class Foo:
            pass

        foo_inst = Foo()
        assert_inst = AssertionError()
        object_inst = object()

        union = UnionType.add(foo_inst, assert_inst)
        compare_types(union, [foo_inst, assert_inst])

        union2 = UnionType(union, object_inst)
        compare_types(union2, [foo_inst, assert_inst, object_inst])

        clone = UnionType.add(foo_inst, assert_inst)
        self.assertFalse(union == union2)
        self.assertTrue(union == clone)

        clone2 = UnionType.add(foo_inst, AssertionError())
        self.assertFalse(union == clone2)