Exemplo n.º 1
0
    def test_failure(self):
        from typecheck import _TC_TypeError, And

        try:
            check_type(And(int, float), "foo")
        except _TC_TypeError, e:
            assert e.right == And(int, float)
            assert e.wrong == str
Exemplo n.º 2
0
    def test_hash(self):
        from typecheck import YieldSeq, And

        eq_tests = [(YieldSeq(int, float), YieldSeq(int, float)),
                    (YieldSeq(And(int, str),
                              float), YieldSeq(And(int, str), float))]

        ne_tests = [(YieldSeq(float, str), YieldSeq(int, float)),
                    (YieldSeq(int, float), YieldSeq(int, int, int, float)),
                    (YieldSeq(int, float, str), YieldSeq(int, float)),
                    (YieldSeq(int, float), YieldSeq(int, float, str)),
                    (YieldSeq(int, float), And(int, float)),
                    (YieldSeq(int, int, int, float), YieldSeq(int, float))]

        self.multipleAssertEqualHashes(eq_tests, ne_tests)
Exemplo n.º 3
0
    def test_success(self):
        from typecheck import Or, And

        # Built-in types
        self.or_type(5)
        self.or_type(7.0)

        class A(object):
            pass  # New-style classes

        class B:
            pass  # Old-style classes

        class C(A, B):
            pass

        check_type(Or(A, B), C())
        check_type(Or(A, B), A())
        check_type(Or(A, B), B())

        # Nested extension classes
        check_type(Or(A, And(A, B)), C())

        # Complex-er types
        check_type(Or((int, int), [int, float]), (5, 6))
Exemplo n.º 4
0
    def test_distinct_parameters(self):
        from typecheck import And

        try:
            And(int, int)
        except TypeError, e:
            self.assertEqual(
                str(e),
                "there must be at least 2 distinct parameters to __init__()")
Exemplo n.º 5
0
    def test_success(self):
        from typecheck import And

        class A:
            pass

        class B:
            pass

        class C(A, B):
            pass

        check_type(And(A, B), C())
Exemplo n.º 6
0
    def test_hash(self):
        from typecheck import Or, And

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

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

        self.multipleAssertEqualHashes(eq_tests, ne_tests)
Exemplo n.º 7
0
 def Xor(cond_1, cond_2):
     return Or(And(cond_1, Not(cond_2)), And(cond_2, Not(cond_1)))
Exemplo n.º 8
0
    def test_equality(self):
        from typecheck import And, Or

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

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

        self.multipleAssertEqual(eq_tests, ne_tests)
Exemplo n.º 9
0
    def test_combined(self):
        from typecheck import And

        and_type = And(Length(3), tuple)
        check_type(and_type, (5, 6, 7))