コード例 #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)))
コード例 #2
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)))
コード例 #3
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)))
コード例 #4
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))
コード例 #5
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)))
コード例 #6
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))
コード例 #7
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)))
コード例 #8
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)))
コード例 #9
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))
コード例 #10
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))
コード例 #11
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))
コード例 #12
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))
コード例 #13
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))
コード例 #14
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))
コード例 #15
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)))
コード例 #16
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)))
コード例 #17
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)))
コード例 #18
0
 def test(self, a: union(int, float)) -> int:
     return 1
コード例 #19
0
 def test(a: union(int, float, Decimal)):
     return a
コード例 #20
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)))
コード例 #21
0
 def test(a: union(int, float)) -> int:
     pass
コード例 #22
0
 def test(a: union(int, float)) -> int:
     pass
コード例 #23
0
 def test_union_is_type(self):
     self.assertIsInstance(union(int, float), type)
コード例 #24
0
 def test(a) -> union(int, float):
     return a
コード例 #25
0
 def test_union_is_type(self):
     self.assertIsInstance(union(int, float), type)
コード例 #26
0
 def test() -> union(int, float):
     pass
コード例 #27
0
 def test() -> union(int, float, bool):
     pass
コード例 #28
0
 def test() -> union(int, float, bool):
     pass
コード例 #29
0
 def test(self) -> union(float, int):
     return 1
コード例 #30
0
 def test(a: union(int, float, Decimal)):
     return a
コード例 #31
0
 def test() -> union(int, float):
     pass
コード例 #32
0
 def test(self, a: union(int, float)) -> int:
     return 1
コード例 #33
0
 def test(self) -> union(int, float):
     return 1
コード例 #34
0
 def test(self) -> union(float, int):
     return 1
コード例 #35
0
 class TestInterface(Interface):
     x = union(int, str)
コード例 #36
0
 def test(self) -> union(int, float):
     return 1
コード例 #37
0
 def test(a) -> union(int, float):
     return a