Changeset 2660
- Timestamp:
- Jun 15, 2010 1:13:16 AM (11 years ago)
- Location:
- coopr.testing/trunk
- Files:
-
- 4 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
coopr.testing/trunk/coopr/testing/__init__.py
r2625 r2660 15 15 import yaml_plugin 16 16 import driver 17 import coopr_driver 18 import colin_driver 19 import pyomo_driver 17 20 18 21 pyutilib.component.core.PluginGlobals.pop_env() -
coopr.testing/trunk/coopr/testing/driver.py
r2626 r2660 1 1 2 __all__ = ['main', 'create_test_suite ']2 __all__ = ['main', 'create_test_suites'] 3 3 4 4 import os … … 6 6 import optparse 7 7 import plugins 8 from pyutilib.misc import Options 8 9 from pyutilib.component.core import ExtensionPoint, PluginGlobals 10 import pyutilib.th as unittest 9 11 10 12 11 def create_test_suite(filename): 12 ep = ExtensionPoint(plugins.ITestDriver) 13 def validate_test_config(suite): 14 tmp = set(suite.keys()) 15 if not tmp.issubset(set(['python','solvers','problems','suites', 'driver'])): 16 raise IOError, "Unexpected test sections: "+str(suite.keys()) 17 # 18 if 'python' in suite: 19 if not type(suite['python']) is list: 20 raise IOError, "Expected list of Python expressions" 21 # 22 if 'solvers' in suite: 23 if not type(suite['solvers']) is dict: 24 raise IOError, "Expected dictionary of solvers" 25 for key in suite['solvers']: 26 if not type(suite['solvers'][key]) is dict: 27 raise IOError, "Expected solvers to have a dictionary of options" 28 # 29 if 'problems' in suite: 30 if not type(suite['problems']) is dict: 31 raise IOError, "Expected dictionary of problems" 32 for key in suite['problems']: 33 if not type(suite['problems'][key]) is dict: 34 raise IOError, "Expected problems to have a dictionary of options" 35 # 36 if 'suites' in suite: 37 if not type(suite['suites']) is dict: 38 raise IOError, "Expected dictionary of suites" 39 for key in suite['suites']: 40 if not type(suite['suites'][key]) is dict: 41 raise IOError, "Expected suites to have a dictionary of options" 42 43 44 45 def create_test_suites(filename, _globals, options=Options): 46 ep = ExtensionPoint(plugins.ITestParser) 13 47 ftype = os.path.splitext(filename)[1] 14 48 if not ftype == '': … … 16 50 service = ep.service(ftype) 17 51 if service is None: 18 raise IOError, "Unknown file type. Cannot load suites from file '%s'" % filename 19 suite = service.load_test_suite(filename) 52 raise IOError, "Unknown file type. Cannot load test configuration from file '%s'" % filename 53 config = service.load_test_config(filename) 54 #service.print_test_config(config) 55 validate_test_config(config) 56 # 57 # Create test driver, which is put in the global namespace 58 # 59 driver = plugins.TestDriverFactory(config['driver']) 60 if driver is None: 61 raise IOError, "Unexpected test driver '%s'" % config['driver'] 62 _globals["test_driver"] = driver 63 # 64 # Evaluate Python expressions 65 # 66 for item in config.get('python',[]): 67 try: 68 eval(item, _globals) 69 except Exception, err: 70 print "ERROR evaluating '%s'" % item 71 # 72 # Generate suite 73 # 74 for suite in config.get('suites',{}): 75 create_test_suite(suite, config, _globals, options) 76 77 78 def create_test_suite(suite, config, _globals, options): 79 # 80 # Skip suite creation if the options category is not in the list of test suite categories 81 # 82 if not (options.category is None or options.category in config['suites'][suite].get('categories',[])): 83 return 84 # 85 # Create test driver 86 # 87 print "X",suite 88 #class tmp(unittest.TestCase): pass 89 _globals["TestSuite_"+suite] = type("TestSuite_"+suite,(unittest.TestCase,),{}) 90 #tmp = _globals["TestSuite_"+suite] 91 # 92 # Create test functions 93 # 94 print "HERE",suite 95 for solver in config['suites'][suite]['solvers']: 96 if 'name' in solver: 97 sname = solver['name'] 98 else: 99 sname = solver['solver'] 100 for problem in config['suites'][suite]['problems']: 101 test_name = sname+"_"+problem 102 print test_name 103 options = Options() 104 options.solver = sname 105 options.problem = problem 106 def fn(name): 107 return test_driver.run_test(name, fn._options) 108 fn._options = options 109 _globals["TestSuite_"+suite].add_fn_test(name=test_name, fn=fn) 110 # 111 # Set the name of this class in the global namespace 112 # 113 print dir(_globals["TestSuite_"+suite]) 114 20 115 21 116 22 117 def main(): 118 23 119 parser = optparse.OptionParser() 24 120 25 121 parser.add_option('-d','--debug', 26 action='store ',122 action='store_true', 27 123 dest='debug', 28 124 default=False, 29 125 help='Set debugging flag') 126 127 parser.add_option('-v','--verbose', 128 action='store_true', 129 dest='verbose', 130 default=False, 131 help='Set flag for verbose output') 132 133 parser.add_option('-q','--quiet', 134 action='store_true', 135 dest='quiet', 136 default=False, 137 help='Set flag for quiet output') 138 139 parser.add_option('--category', 140 action='store', 141 dest='category', 142 default=None, 143 help='Define the category of the test suite that is executed') 30 144 31 145 options, args = parser.parse_args(sys.argv) … … 36 150 37 151 for file in args[1:]: 38 create_test_suite(file) 152 create_test_suites(file, globals(), options) 153 154 tmp = [args[0]] 155 if options.quiet: 156 tmp.append('-q') 157 if options.verbose or options.debug: 158 tmp.append('-v') 159 #tmp += args 160 sys.argv = tmp 161 print "X",sys.argv 162 print "X",globals().keys() 163 print "X",dir(globals()['TestSuite_ps']) 164 print dir(globals()['__name__']) 165 unittest.main(module=globals()['__name__']) 39 166 40 167 -
coopr.testing/trunk/coopr/testing/plugins.py
r2626 r2660 1 1 2 __all__ = ['ITestDriver' ]2 __all__ = ['ITestDriver', 'TestDriverFactory', 'ITestParser'] 3 3 4 4 from pyutilib.component.core import * 5 5 6 class ITest Driver(Interface):6 class ITestParser(Interface): 7 7 8 def load_test_suite(self, filename): 8 def load_test_config(self, filename): 9 pass 10 11 def print_test_config(self, repn): 9 12 pass 10 13 11 14 15 class ITestDriver(Interface): 16 17 def run_test(self, options): 18 pass 19 20 TestDriverFactory = CreatePluginFactory(ITestDriver) -
coopr.testing/trunk/coopr/testing/yaml_plugin.py
r2626 r2660 10 10 11 11 12 class YamlTest Driver(SingletonPlugin):12 class YamlTestParser(SingletonPlugin): 13 13 14 implements(plugins.ITest Driver)14 implements(plugins.ITestParser) 15 15 16 16 def __init__(self, **kwds): … … 18 18 self.name='yml' 19 19 20 def load_test_ suite(self, filename):20 def load_test_config(self, filename): 21 21 INPUT = open(filename, 'r') 22 22 repn = yaml.load(INPUT, yaml.SafeLoader) … … 24 24 return repn 25 25 26 def print_test_config(self, repn): 27 print repn 28 -
coopr.testing/trunk/setup.py
r2625 r2660 70 70 entry_points=""" 71 71 [console_scripts] 72 coopr_test_driver = coopr.testing. driver:main72 coopr_test_driver = coopr.testing.coopr_test_driver:main 73 73 """ 74 74 )
Note: See TracChangeset
for help on using the changeset viewer.