def assert_grammar_typechecking(grammar_types, test_obj):
 class BadType(object, ):
  pass
 for (name, objects) in grammar_types:
  for obj in objects:
   tmp_obj = obj()
   setattr(test_obj, name, tmp_obj)
   nt.assert_equal(getattr(test_obj, name), tmp_obj)
   bad_obj = BadType()
   nt.assert_raises_regexp(ValueError, ((name + '.*') + obj.__name__), setattr, test_obj, name, bad_obj)
   nt.assert_equal(getattr(test_obj, name), tmp_obj)

def assert_grammar_typechecking ( grammar_types , test_obj ) : class BadType ( object , ) : pass for ( name , objects ) in grammar_types : for obj in objects : tmp_obj = obj ( ) setattr ( test_obj , name , tmp_obj ) nt . assert_equal ( getattr ( test_obj , name ) , tmp_obj ) bad_obj = BadType ( ) nt . assert_raises_regexp ( ValueError , ( ( name + '.*' ) + obj . __name__ ) , setattr , test_obj , name , bad_obj ) nt . assert_equal ( getattr ( test_obj , name ) , tmp_obj )
assert that the grammar fields of a test object are correctly type-checked .