Changeset 430
- Timestamp:
- 07/08/05 00:49:12
- Files:
-
- trunk/cherrypy/test/test.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/test/test.py
r429 r430 31 31 import os, os.path 32 32 import unittest 33 34 try: 35 set 36 except NameError: 37 from sets import Set as set 33 38 34 39 … … 188 193 } 189 194 190 import sys191 192 195 def help(): 193 196 print """CherryPy Test Program 194 197 Usage: 195 198 test.py -mode testName1 testName2 testName... 196 199 197 200 modes: wsgi, severless, native, all 198 201 default: wsgi 199 202 """ 200 203 201 204 print ' tests:' 202 205 for testString in testDict: 203 206 print ' ', testString 204 207 205 208 206 209 class BadArgument(Exception): 207 def __init__(self, arg): 208 self.arg = arg 209 def __str__(self): 210 return 'Error:\n %s is not a valid option.' % self.arg 211 212 class DisplayHelp(Exception): pass 213 214 def getOptions(): 215 216 argSet = set([arg.lower() for arg in sys.argv[1:]]) 217 218 if '-help' in sys.argv: 210 pass 211 212 class DisplayHelp(Exception): 213 pass 214 215 216 def getOptions(args): 217 218 argSet = set([arg.lower() for arg in args]) 219 220 if '-help' in args: 219 221 raise DisplayHelp 220 222 … … 222 224 if '-all' in argSet: 223 225 servers.update(['wsgi', 'native', 'serverless']) 224 elif '-wsgi' in argSet:225 servers.add('wsgi')226 elif '-native' in argSet:227 servers.add('native')228 elif '-serverless' in argSet:229 servers.add('serverless')230 226 else: 231 servers.add('wsgi') 232 227 if '-native' in argSet: 228 servers.add('native') 229 if '-serverless' in argSet: 230 servers.add('serverless') 231 if '-wsgi' in argSet or not servers: 232 servers.add('wsgi') 233 233 argSet.difference_update(['-wsgi', '-native', '-serverless', '-all']) 234 234 235 cover = ("-cover" in argSet) 236 profile = ("-profile" in argSet) 237 if cover and profile: 238 raise BadArgument('Bad Arguments: you cannot run the profiler and the coverage tool at the same time.') 239 argSet.difference_update(['-cover', '-profile']) 240 235 241 tests = [] 236 242 for testString, test in testDict.iteritems(): … … 238 244 tests.append(testDict[testString]) 239 245 argSet.discard(testString.lower()) 240 241 246 if not tests: 242 247 tests = testDict.values() 243 248 244 249 if len(argSet): 245 for arg in sys.argv: 246 print arg, arg.lower(), arg.lower() in argSet 250 for arg in args: 247 251 if arg.lower() in argSet: 248 raise BadArgument(arg) 249 return (servers, tests) 250 251 def main(): 252 try: 253 servers, testList = getOptions() 254 runTests(servers, testList) 255 except DisplayHelp: 256 help() 257 except BadArgument, argError: 258 print argError 259 260 def runTests(servers, testList): 252 raise BadArgument('Bad Argument: %s is not a valid option.' % arg) 253 return (servers, tests, cover, profile) 254 255 256 def runTests(servers, testList, cover=False, profile=False): 261 257 # Place our current directory's parent (cherrypy/) at the beginning 262 258 # of sys.path, so that all imports are from our current directory. … … 265 261 sys.path.insert(0, os.path.normpath(os.path.join(curpath, '../../'))) 266 262 267 # Start the coverage tool before importing cherrypy, so module-level 268 # global statements are covered. 269 try: 270 from coverage import the_coverage as coverage 271 coverage.cache_default = c = os.path.join(os.path.dirname(__file__), 272 "../lib/coverage.cache") 273 if c and os.path.exists(c): 274 os.remove(c) 275 coverage.start() 276 except ImportError: 277 coverage = None 263 if cover: 264 # Start the coverage tool before importing cherrypy, so module-level 265 # global statements are covered. 266 try: 267 from coverage import the_coverage as coverage 268 coverage.cache_default = c = os.path.join(os.path.dirname(__file__), 269 "../lib/coverage.cache") 270 if c and os.path.exists(c): 271 os.remove(c) 272 coverage.start() 273 except ImportError: 274 coverage = None 278 275 279 276 global cherrypy, helper … … 302 299 } 303 300 301 if cover: 302 cherrypy.codecoverage = True 303 304 if profile: 305 server_conf['profiling.on'] = True 306 304 307 if 'serverless' in servers: 305 308 print 306 309 print "Running testList: Serverless" 307 cherrypy.codecoverage = True308 310 run_test_suite(testList, None, server_conf) 309 cherrypy.codecoverage = False310 311 311 312 if 'native' in servers: … … 317 318 print 318 319 print "Running testList: Native WSGI Server" 319 server_conf['profiling.on'] = True320 320 run_test_suite(testList, "cherrypy._cpwsgi.WSGIServer", server_conf) 321 322 if profile or cover: 323 print 324 325 if profile: 321 326 del server_conf['profiling.on'] 322 323 print 324 325 if coverage: 326 coverage.save() 327 report_coverage(coverage) 328 print "run /cherrypy/lib/covercp.py as a script to serve coverage results on port 8080" 329 330 print "run /cherrypy/lib/profiler.py as a script to serve profiling results on port 8080" 327 print "run /cherrypy/lib/profiler.py as a script to serve profiling results on port 8080" 328 329 if cover: 330 cherrypy.codecoverage = False 331 if coverage: 332 coverage.save() 333 report_coverage(coverage) 334 print "run /cherrypy/lib/covercp.py as a script to serve coverage results on port 8080" 331 335 332 336 print 333 337 raw_input('hit enter') 334 338 339 335 340 if __name__ == '__main__': 336 main() 341 try: 342 servers, testList, cover, profile = getOptions(sys.argv[1:]) 343 except DisplayHelp: 344 help() 345 except BadArgument, argError: 346 print argError 347 else: 348 runTests(servers, testList, cover, profile)

