def __init__( self, clazz, name ): type_isinstance( PepTypeMatcher, clazz ) type_is( str, name ) PepValue.__init__( self ) self.clazz = clazz self.name = name self.namespace = self.clazz.runtime_namespace( self, False )
def Does_nothing_on_instance_of_subsubclass__test(): type_isinstance(B, sobsob)
def Throws_when_primitive_type_does_not_match__test(): with assert_raises(AssertionError) as cm: type_isinstance(int, "foo") assert_regexp_matches(str(cm.exception), "^type_isinstance check failed") assert_regexp_matches(str(cm.exception), "int but found") assert_regexp_matches(str(cm.exception), "str.$")
def Throws_when_class_does_not_match__test(): with assert_raises(AssertionError) as cm: type_isinstance(B, a) assert_regexp_matches(str(cm.exception), "^type_isinstance check failed") assert_regexp_matches(str(cm.exception), "B but found") assert_regexp_matches(str(cm.exception), "A.$")
def Does_nothing_when_primitive_type_matches__test(): type_isinstance(int, 3)
def Does_nothing_when_class_matches__test(): type_isinstance(A, a)
def Fails_when_first_arg_is_not_a_type_but_an_instance__test(): with assert_raises(AssertionError): type_isinstance(a, a)
def Fails_when_first_arg_is_not_a_type_but_an_int__test(): with assert_raises(AssertionError) as cm: type_isinstance(3, a) assert_regexp_matches(str(cm.exception), "^Wrong arguments")