Esempio n. 1
0
    def test_issubclass_union(self):
        self.assertTrue(issubclass(union(int, float), union(int, float)))
        self.assertTrue(issubclass(union(int, float), union(float, int)))
        self.assertTrue(issubclass(union(int, float), union(int, float, bool)))

        self.assertFalse(issubclass(union(int, float), union(int, str)))
        self.assertFalse(issubclass(union(int, str, float), union(int, float)))
Esempio n. 2
0
    def test_issubclass_single_class(self):
        class Test1: pass
        class Test2: pass
        class Other: pass

        self.assertTrue(issubclass(Test1, union(Test1, Test2)))
        self.assertTrue(issubclass(Test2, union(Test1, Test2)))

        self.assertFalse(issubclass(Other, union(Test1, Test2)))
Esempio n. 3
0
    def test_isinstance_classes(self):

        class Test1: pass
        class Test2: pass
        class Other: pass

        self.assertIsInstance(Test1(), union(Test1, Test2))
        self.assertIsInstance(Test2(), union(Test1, Test2))

        self.assertNotIsInstance(Other(), union(Test1, Test2))
Esempio n. 4
0
    def test_issubclass_single_interface(self):

        class Test1(Interface):
            def test1(self) -> int:
                pass

        class Test2(Interface):
            def test2(self) -> str:
                pass

        class Other(Interface): pass
        class Other2: pass

        self.assertTrue(issubclass(Test1, union(Test1, Test2)))
        self.assertTrue(issubclass(Test2, union(Test1, Test2)))

        self.assertFalse(issubclass(Other, union(Test1, Test2)))
        self.assertFalse(issubclass(Other2, union(Test1, Test2)))
Esempio n. 5
0
    def test_isinstance_interfaces(self):

        class Test1(Interface):
            def test1() -> int:
                pass
        class Test1Implementation:
            def test1(self) -> int:
                return 1
        class Test2(Interface):
            def test2() -> str:
                pass
        class Test2Implementation:
            def test2(self) -> str:
                return 1
        class Other: pass

        self.assertIsInstance(Test1Implementation(), union(Test1, Test2))
        self.assertIsInstance(Test2Implementation(), union(Test1, Test2))

        self.assertNotIsInstance(Other(), union(Test1, Test2))
Esempio n. 6
0
    def test_isinstance_mixed(self):

        class Test1:
            pass

        class Test2(Interface):
            def test2() -> str:
                pass

        class Test2Implementation:
            def test2() -> str:
                return 1

        class Other:
            pass

        self.assertIsInstance(1, union(int, Test1, Test2))
        self.assertIsInstance(Test1(), union(int, Test1, Test2))
        self.assertIsInstance(Test2Implementation(), union(int, Test1, Test2))

        self.assertNotIsInstance('string', union(int, Test1, Test2))
        self.assertNotIsInstance(Other(), union(int, Test1, Test2))
Esempio n. 7
0
    def test_isinstance_bultin_types(self):
        self.assertIsInstance(1, union(int, float))
        self.assertIsInstance(1.2, union(int, float))

        self.assertNotIsInstance('string', union(int, float))
        self.assertNotIsInstance([], union(int, float))
        self.assertNotIsInstance(tuple(), union(int, float))
        self.assertNotIsInstance({}, union(int, float))
Esempio n. 8
0
    def test_issubclass_single_mixed(self):

        class Test1(Interface):
            def test1(self) -> int:
                pass

        class Test2:
            pass

        self.assertTrue(issubclass(int, union(int, Test1, Test2)))
        self.assertTrue(issubclass(Test1, union(int, Test1, Test2)))
        self.assertTrue(issubclass(Test2, union(int, Test1, Test2)))

        self.assertTrue(issubclass(int, union(int, Test1, Test2)))
        self.assertTrue(issubclass(Test1, union(int, Test1, Test2)))
        self.assertTrue(issubclass(Test2, union(int, Test1, Test2)))
Esempio n. 9
0
 def test(self) -> union(float, int):
     return 1
Esempio n. 10
0
 def test() -> union(int, float, bool):
     pass
Esempio n. 11
0
 def test(self, a: union(int, float)) -> int:
     return 1
Esempio n. 12
0
 def test(a: union(int, float)) -> int:
     pass
Esempio n. 13
0
 def test(a: union(int, float, Decimal)):
     return a
Esempio n. 14
0
 def test_union_is_type(self):
     self.assertIsInstance(union(int, float), type)
Esempio n. 15
0
    def test_issubclass_single_builtin_type(self):
        self.assertTrue(issubclass(int, union(int, float)))
        self.assertTrue(issubclass(float, union(int, float)))

        self.assertFalse(issubclass(str, union(int, float)))
        self.assertFalse(issubclass(list, union(int, float)))
Esempio n. 16
0
 def test() -> union(int, float):
     pass
Esempio n. 17
0
 def test(self) -> union(int, float):
     return 1
Esempio n. 18
0
 def test(a) -> union(int, float):
     return a