示例#1
0
    def test_failure_2(self):
        from typecheck import _TC_TypeError, Not

        try:
            check_type(Not(int, float), 4.0)
        except _TC_TypeError, e:
            assert e.right == Not(int, float)
            assert e.wrong == float
示例#2
0
    def test_success(self):
        from typecheck import Not

        check_type(Not(int), 4.0)
        check_type(Not(int, float), 'four')

        class A:
            pass

        class B:
            pass

        class C:
            pass

        check_type(Not(A, B, int), C())
示例#3
0
    def test_constructor(self):
        from typecheck import Not

        try:
            Not()
        except TypeError, e:
            assert str(e) == "__init__() takes at least 2 arguments (1 given)"
示例#4
0
    def test_failure_3(self):
        from typecheck import _TC_TypeError, Not

        class A:
            pass

        class B:
            pass

        class C(A, B):
            pass

        try:
            check_type(Not(A, B, int), C())
        except _TC_TypeError, e:
            assert e.right == Not(A, B, int)
            assert e.wrong == C
示例#5
0
 def Xor(cond_1, cond_2):
     return Or(And(cond_1, Not(cond_2)), And(cond_2, Not(cond_1)))
示例#6
0
    def test_hash(self):
        from typecheck import Not, Or

        eq_tests = [(Not(int, float), Not(int, float)),
                    (Not(int, float), Not(int, int, int, float)),
                    (Not(int, int, int, float), Not(int, float)),
                    (Not(int, float), Not(float, int)),
                    (Not(Not(int, str), float), Not(float, Not(str, int)))]

        ne_tests = [(Not(float, str), Not(int, float)),
                    (Not(int, float, str), Not(int, float)),
                    (Not(int, float), Not(int, float, str)),
                    (Not(int, float), Or(int, float)),
                    (Not(Not(int, str), float), Not(int, str, float)),
                    (Not(Not(int, float), Not(str, int)), Not(int, float,
                                                              str))]

        self.multipleAssertEqualHashes(eq_tests, ne_tests)