Пример #1
0
    def test_success_userdef_classes_newstyle(self):
        from typecheck import AtomicType

        class A(object):
            pass

        class B(A):
            pass

        check_type(AtomicType(A), A())
        check_type(AtomicType(A), B())
        check_type(AtomicType(B), B())
Пример #2
0
    def test_hash(self):
        from typecheck import AtomicType

        class A(object):
            pass

        class B(A):
            pass

        eq_tests = [(AtomicType(int), AtomicType(int)),
                    (AtomicType(A), AtomicType(A)),
                    (AtomicType(B), AtomicType(B))]

        ne_tests = [(AtomicType(int), AtomicType(float)),
                    (AtomicType(A), AtomicType(B))]

        self.multipleAssertEqualHashes(eq_tests, ne_tests)
Пример #3
0
    def test_failure(self):
        from typecheck import AtomicType, _TC_TypeError

        try:
            check_type(AtomicType(int), 7.0)
        except _TC_TypeError, e:
            assert e.right == int
            assert e.wrong == float
Пример #4
0
    def __typecheck__(self, func, to_check):
        AtomicType.__typecheck__(self, func, to_check)

        if len(to_check) > 0:
            raise _TC_LengthError(len(to_check), 0)
Пример #5
0
    def __init__(self, type):
        if not hasattr(type, '__len__'):
            raise TypeError(
                "Can only assert emptyness for types with __len__ methods")

        AtomicType.__init__(self, type)
Пример #6
0
    def test_success_builtin_types(self):
        from typecheck import AtomicType

        check_type(AtomicType(int), 7)
        check_type(AtomicType(float), 7.0)