<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function , absolute_import <EOL> from . . externals . six import with_metaclass <EOL> from nose . tools import assert_equal <EOL> class validator2test ( type ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( mcs , name , bases , dict ) : <EOL> klass = type . __new__ ( mcs , name , bases , dict ) <EOL> def make_test ( name , validator ) : <EOL> def meth ( self ) : <EOL> for imaker , params in self . obj_params ( ) : <EOL> validator ( self , imaker , params ) <EOL> meth . __name__ = '<STR_LIT>' + name [ len ( '<STR_LIT>' ) : ] <EOL> meth . __doc__ = '<STR_LIT>' + name <EOL> return meth <EOL> for name in dir ( klass ) : <EOL> if not name . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> test_meth = make_test ( name , getattr ( klass , name ) ) <EOL> setattr ( klass , test_meth . __name__ , test_meth ) <EOL> return klass <EOL> class ValidateAPI ( with_metaclass ( validator2test ) ) : <EOL> """<STR_LIT>""" <EOL> class TestValidateSomething ( ValidateAPI ) : <EOL> """<STR_LIT>""" <EOL> def obj_params ( self ) : <EOL> """<STR_LIT>""" <EOL> class C ( object ) : <EOL> def __init__ ( self , var ) : <EOL> self . var = var <EOL> def get_var ( self ) : <EOL> return self . var <EOL> yield C ( <NUM_LIT:5> ) , { '<STR_LIT>' : <NUM_LIT:5> } <EOL> yield C ( '<STR_LIT>' ) , { '<STR_LIT>' : '<STR_LIT>' } <EOL> def validate_something ( self , obj , params ) : <EOL> """<STR_LIT>""" <EOL> assert_equal ( obj . var , params [ '<STR_LIT>' ] ) <EOL> assert_equal ( obj . get_var ( ) , params [ '<STR_LIT>' ] ) <EOL> class TestRunAllTests ( ValidateAPI ) : <EOL> """<STR_LIT>""" <EOL> run_tests = [ ] <EOL> def obj_params ( self ) : <EOL> yield <NUM_LIT:1> , <NUM_LIT:2> <EOL> def validate_first ( self , obj , param ) : <EOL> self . run_tests . append ( '<STR_LIT>' ) <EOL> def validate_second ( self , obj , param ) : <EOL> self . run_tests . append ( '<STR_LIT>' ) <EOL> def teardown ( ) : <EOL> assert_equal ( TestRunAllTests . run_tests , [ '<STR_LIT>' , '<STR_LIT>' ] ) </s>
