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())
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)
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
def __typecheck__(self, func, to_check): AtomicType.__typecheck__(self, func, to_check) if len(to_check) > 0: raise _TC_LengthError(len(to_check), 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)
def test_success_builtin_types(self): from typecheck import AtomicType check_type(AtomicType(int), 7) check_type(AtomicType(float), 7.0)