Changeset 483
- Timestamp:
- 07/18/05 18:01:35
- Files:
-
- trunk/cherrypy/config.py (modified) (3 diffs)
- trunk/cherrypy/lib/covercp.py (modified) (2 diffs)
- trunk/cherrypy/test/helper.py (modified) (1 diff)
- trunk/cherrypy/test/test.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/config.py
r474 r483 174 174 fp.close() 175 175 176 def _load(configFile, override=True): 177 """ Convert an INI file to a dictionary. If override is false, 178 values already in the configMap will not be changed. 179 """ 176 def dict_from_config_file(configFile): 177 """ Convert an INI file to a dictionary. """ 180 178 181 179 # Parse config file … … 186 184 configParser.read(configFile) 187 185 188 # Load INI file into cherrypy.configMap 186 # Load INI file into a dict 187 result = {} 189 188 for section in configParser.sections(): 190 if section not in configMap:191 configMap[section] = {}189 if section not in result: 190 result[section] = {} 192 191 for option in configParser.options(section): 193 192 value = configParser.get(section, option) … … 198 197 (repr(section), repr(option), repr(value))) 199 198 raise _cperror.WrongConfigValue, msg 199 result[section][option] = value 200 return result 201 202 203 def _load(configFile, override=True): 204 """ Merge an INI file into configMap. If override is false, 205 values already in the configMap will not be changed. 206 """ 207 208 conf = dict_from_config_file(configFile) 209 210 # Load new conf into cherrypy.configMap 211 for section, options in conf.iteritems(): 212 bucket = configMap.setdefault(section, {}) 213 for key, value in options.iteritems(): 200 214 if override: 201 configMap[section][option] = value215 bucket[key] = value 202 216 else: 203 configMap[section].setdefault(option, value) 217 bucket.setdefault(key, value) 218 204 219 205 220 def outputConfigMap(): trunk/cherrypy/lib/covercp.py
r425 r483 29 29 """Code-coverage tools for CherryPy. 30 30 31 To use this module, or the coverage tools in the test suite, 32 you need to download 'coverage.py', either Gareth Rees' original 33 implementation: 34 http://www.garethrees.org/2001/12/04/python-coverage/ 35 36 or Ned Batchelder's enhanced version: 37 http://www.nedbatchelder.com/code/modules/coverage.html 38 31 39 Set "cherrypy.codecoverage = True" to turn on coverage tracing. 32 40 Then, use the serve() function to browse the results in a web browser. … … 51 59 52 60 except ImportError: 53 # This will raise errors that need to be trapped downstream 61 # Setting coverage to None will raise errors 62 # that need to be trapped downstream. 54 63 coverage = None 64 55 65 import warnings 56 66 warnings.warn("No code coverage will be performed; coverage.py could not be imported.") trunk/cherrypy/test/helper.py
r482 r483 194 194 if conf is None: 195 195 conf = {} 196 ## conf = {'global': {'server.socketHost': HOST,197 ## 'server.socketPort': PORT,198 ## 'server.protocolVersion': "HTTP/1.1",199 ## 'server.threadPool': 10,200 ## 'server.logToScreen': False,201 ## 'server.environment': "production",202 ## }203 ## }204 ## if server is None:205 ## server = "cherrypy._cphttpserver.embedded_server"206 196 if isinstance(conf, basestring): 207 197 # assume it's a filename trunk/cherrypy/test/test.py
r480 r483 37 37 38 38 39 testDict = { 40 'baseurlFilter' : 'test_baseurl_filter', 41 'cacheFilter' : 'test_cache_filter', 42 'combinedFilters' : 'test_combinedfilters', 43 'core' : 'test_core', 44 'decodingEncodingFilter' : 'test_decodingencoding_filter', 45 'gzipFilter' : 'test_gzip_filter', 46 'logDebugInfoFilter' : 'test_logdebuginfo_filter', 47 'objectMapping' : 'test_objectmapping', 48 'staticFilter' : 'test_static_filter', 49 'tutorials' : 'test_tutorials', 50 'virtualHostFilter' : 'test_virtualhost_filter', 51 ## 'sessionFilter' : 'test_session_filter' 52 } 53 54 55 def help(): 39 def help(testList): 56 40 print """CherryPy Test Program 57 41 Usage: 58 test.py -mode testName1 testName2 testName... 59 60 modes: wsgi, severless, native, all 61 default: wsgi 42 test.py -mode -cover -profile -1.1 testName1 testName2 testName... 43 44 modes: wsgi, severless, native, all (default is wsgi) 45 46 cover: turns on code-coverage tool 47 48 profile: turns on profiling tool 49 50 1.1: use HTTP/1.1 servers instead of default HTTP/1.0 62 51 """ 63 52 64 53 print ' tests:' 65 for testString in testDict:66 print ' ', testString54 for name in testList: 55 print ' ', name 67 56 68 57 … … 76 65 class Options: 77 66 78 def __init__(self, args ):67 def __init__(self, args, testList): 79 68 argSet = set([arg.lower() for arg in args]) 80 69 … … 109 98 # All remaining args should be test names. 110 99 tests = [] 111 for testString, test in testDict.iteritems():112 if testString.lower() in argSet:113 tests.append( testDict[testString])114 argSet.discard( testString.lower())100 for name in testList: 101 if ("-" + name) in argSet: 102 tests.append(name) 103 argSet.discard("-" + name) 115 104 if not tests: 116 tests = test Dict.values()105 tests = testList 117 106 self.tests = tests 118 107 … … 122 111 raise BadArgument('Bad Argument: %s is not a valid option.' % arg) 123 112 124 125 def main(opts): 126 # Place our current directory's parent (cherrypy/) at the beginning 127 # of sys.path, so that all imports are from our current directory. 128 localDir = os.path.dirname(__file__) 129 curpath = os.path.normpath(os.path.join(os.getcwd(), localDir)) 130 sys.path.insert(0, os.path.normpath(os.path.join(curpath, '../../'))) 131 113 def get_coverage(): 114 """get_coverage() -> a coverage instance. 115 116 To use this feature, or the coverage server in cherrypy/lib/covercp, 117 you need to download 'coverage.py', either Gareth Rees' original 118 implementation: 119 http://www.garethrees.org/2001/12/04/python-coverage/ 120 121 or Ned Batchelder's enhanced version: 122 http://www.nedbatchelder.com/code/modules/coverage.html 123 124 If neither module is found in PYTHONPATH, this module returns None. 125 """ 126 try: 127 from coverage import the_coverage as coverage 128 c = os.path.join(os.path.dirname(__file__), "../lib/coverage.cache") 129 coverage.cache_default = c 130 if c and os.path.exists(c): 131 os.remove(c) 132 coverage.start() 133 except ImportError: 134 coverage = None 135 return coverage 136 137 138 def main(opts, conf=None, includeNotReady=False): 132 139 if opts.cover: 133 140 # Start the coverage tool before importing cherrypy, 134 141 # so module-level global statements are covered. 135 try: 136 from coverage import the_coverage as coverage 137 coverage.cache_default = c = os.path.join(os.path.dirname(__file__), 138 "../lib/coverage.cache") 139 if c and os.path.exists(c): 140 os.remove(c) 141 coverage.start() 142 except ImportError: 143 coverage = None 142 coverage = get_coverage() 144 143 145 144 import cherrypy … … 150 149 from cherrypy.test import helper 151 150 152 class NotReadyTest(helper.CPWebCase): 153 def testNotReadyError(self): 154 # Without having called "cherrypy.server.start()", we should 155 # get a NotReady error 156 class Root: pass 157 cherrypy.root = Root() 158 self.assertRaises(cherrypy.NotReady, self.getPage, "/") 159 helper.CPTestRunner.run(NotReadyTest("testNotReadyError")) 160 161 server_conf = {'global': {'server.socketHost': helper.HOST, 162 'server.socketPort': helper.PORT, 163 'server.protocolVersion': opts.protocol, 164 'server.threadPool': 10, 165 'server.logToScreen': False, 166 'server.environment': "production", 167 } 168 } 151 if includeNotReady: 152 class NotReadyTest(helper.CPWebCase): 153 def testNotReadyError(self): 154 # Without having called "cherrypy.server.start()", we should 155 # get a NotReady error 156 class Root: pass 157 cherrypy.root = Root() 158 self.assertRaises(cherrypy.NotReady, self.getPage, "/") 159 helper.CPTestRunner.run(NotReadyTest("testNotReadyError")) 160 161 if conf is None: 162 conf = {'global': {'server.socketHost': helper.HOST, 163 'server.socketPort': helper.PORT, 164 'server.threadPool': 10, 165 'server.logToScreen': False, 166 'server.environment': "production", 167 } 168 } 169 elif isinstance(conf, basestring): 170 conf = cherrypy.config.dict_from_config_file(conf) 171 172 conf['server.protocolVersion'] = opts.protocol 169 173 170 174 if opts.cover: … … 172 176 173 177 if opts.profile: 174 server_conf['profiling.on'] = True178 conf['profiling.on'] = True 175 179 176 180 if 'serverless' in opts.servers: 177 181 print 178 182 print "Running tests: Serverless" 179 helper.run_test_suite(opts.tests, None, server_conf)183 helper.run_test_suite(opts.tests, None, conf) 180 184 181 185 if 'native' in opts.servers: … … 184 188 helper.run_test_suite(opts.tests, 185 189 "cherrypy._cphttpserver.embedded_server", 186 server_conf)190 conf) 187 191 188 192 if 'wsgi' in opts.servers: … … 191 195 helper.run_test_suite(opts.tests, 192 196 "cherrypy._cpwsgi.WSGIServer", 193 server_conf)197 conf) 194 198 195 199 if opts.profile or opts.cover: … … 197 201 198 202 if opts.profile: 199 del server_conf['profiling.on']203 del conf['profiling.on'] 200 204 print "run /cherrypy/lib/profiler.py as a script to serve profiling results on port 8080" 201 205 … … 212 216 213 217 if __name__ == '__main__': 218 219 testList = [ 220 'test_baseurl_filter', 221 'test_cache_filter', 222 'test_combinedfilters', 223 'test_core', 224 'test_decodingencoding_filter', 225 'test_gzip_filter', 226 'test_logdebuginfo_filter', 227 'test_objectmapping', 228 'test_static_filter', 229 'test_tutorials', 230 'test_virtualhost_filter', 231 ## 'test_session_filter', 232 ] 233 214 234 try: 215 opts = Options(sys.argv[1:] )235 opts = Options(sys.argv[1:], testList) 216 236 except DisplayHelp: 217 help( )237 help(testList) 218 238 except BadArgument, argError: 219 239 print argError 220 240 else: 221 main(opts) 241 # Place our current directory's parent (cherrypy/) at the beginning 242 # of sys.path, so that all imports are from our current directory. 243 localDir = os.path.dirname(__file__) 244 curpath = os.path.normpath(os.path.join(os.getcwd(), localDir)) 245 sys.path.insert(0, os.path.normpath(os.path.join(curpath, '../../'))) 246 247 main(opts, includeNotReady=True)

