Changeset 474
- Timestamp:
- 07/16/05 21:37:15
- Files:
-
- trunk/cherrypy/config.py (modified) (4 diffs)
- trunk/cherrypy/test/helper.py (modified) (2 diffs)
- trunk/cherrypy/test/test.py (modified) (9 diffs)
- trunk/cherrypy/test/test_baseurl_filter.py (modified) (2 diffs)
- trunk/cherrypy/test/test_cache_filter.py (modified) (2 diffs)
- trunk/cherrypy/test/test_combinedfilters.py (modified) (2 diffs)
- trunk/cherrypy/test/test_core.py (modified) (2 diffs)
- trunk/cherrypy/test/test_decodingencoding_filter.py (modified) (2 diffs)
- trunk/cherrypy/test/test_gzip_filter.py (modified) (2 diffs)
- trunk/cherrypy/test/test_logdebuginfo_filter.py (modified) (2 diffs)
- trunk/cherrypy/test/test_objectmapping.py (modified) (2 diffs)
- trunk/cherrypy/test/test_session_filter.py (modified) (1 diff)
- trunk/cherrypy/test/test_static_filter.py (modified) (2 diffs)
- trunk/cherrypy/test/test_tutorials.py (modified) (1 diff)
- trunk/cherrypy/test/test_virtualhost_filter.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/config.py
r465 r474 62 62 reset() 63 63 64 def update(updateMap=None, file=None, override =True):64 def update(updateMap=None, file=None, override=True): 65 65 """ Update the configMap from a dictionary or a config file. 66 66 If override is True then the update will not modify … … 158 158 that raises an exception if the file cannot be read 159 159 """ 160 160 161 def optionxform(self, optionstr): 161 162 return optionstr 163 162 164 def read(self, filenames): 163 165 if isinstance(filenames, basestring): … … 172 174 fp.close() 173 175 174 def _load(configFile = None, override =True):175 """ Convert an INI file to a dictionary. If override is false176 Values allready in the configMap will not be changed.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. 177 179 """ 178 180 … … 180 182 configParser = CaseSensitiveConfigParser() 181 183 if hasattr(configFile, 'read'): 182 cherrypy.log("Reading infos from configFile stream", 'CONFIG')183 184 configParser.readfp(configFile) 184 185 else: 185 cherrypy.log("Reading infos from configFile: %s" % configFile, 'CONFIG')186 186 configParser.read(configFile) 187 187 trunk/cherrypy/test/helper.py
r471 r474 28 28 29 29 import os, os.path 30 import sys 30 31 import time 31 32 import socket … … 116 117 else: 117 118 webtest.WebCase.getPage(self, url, headers, method, body) 119 120 CPTestLoader = webtest.ReloadingTestLoader() 121 CPTestRunner = webtest.TerseTestRunner(verbosity=2) 122 123 124 def report_coverage(coverage, basedir=None): 125 if not basedir: 126 localDir = os.path.dirname(__file__) 127 basedir = os.path.normpath(os.path.join(os.getcwd(), localDir, '../')) 128 129 coverage.get_ready() 130 morfs = [x for x in coverage.cexecuted if x.startswith(basedir.lower())] 131 132 total_statements = 0 133 total_executed = 0 134 135 print 136 print "CODE COVERAGE (this might take a while)", 137 for morf in morfs: 138 sys.stdout.write(".") 139 sys.stdout.flush() 140 name = os.path.split(morf)[1] 141 try: 142 _, statements, _, missing, readable = coverage.analysis2(morf) 143 n = len(statements) 144 m = n - len(missing) 145 total_statements = total_statements + n 146 total_executed = total_executed + m 147 except KeyboardInterrupt: 148 raise 149 except: 150 # No, really! We truly want to ignore any other errors. 151 pass 152 153 pc = 100.0 154 if total_statements > 0: 155 pc = 100.0 * total_executed / total_statements 156 157 print ("\nTotal: %s Covered: %s Percent: %2d%%" 158 % (total_statements, total_executed, pc)) 159 160 161 def run_test_suite(moduleNames, server, conf): 162 if isinstance(conf, basestring): 163 # assume it's a filename 164 cherrypy.config.update(file=conf) 165 else: 166 cherrypy.config.update(conf.copy()) 167 startServer(server) 168 for testmod in moduleNames: 169 # Must run each module in a separate suite, 170 # because each module uses/overwrites cherrypy globals. 171 cherrypy.config.reset() 172 if isinstance(conf, basestring): 173 cherrypy.config.update(file=conf) 174 else: 175 cherrypy.config.update(conf.copy()) 176 cherrypy._cputil._cpInitDefaultFilters() 177 178 suite = CPTestLoader.loadTestsFromName(testmod) 179 CPTestRunner.run(suite) 180 stopServer() 181 182 183 def testmain(server=None, conf={}): 184 if isinstance(conf, basestring): 185 # assume it's a filename 186 cherrypy.config.update(file=conf) 187 else: 188 cherrypy.config.update(conf.copy()) 189 190 startServer(server) 191 try: 192 cherrypy._cputil._cpInitDefaultFilters() 193 webtest.main() 194 finally: 195 # webtest.main == unittest.main, which raises SystemExit, 196 # so put stopServer in a finally clause 197 stopServer() 198 trunk/cherrypy/test/test.py
r467 r474 36 36 from sets import Set as set 37 37 38 39 CPTestLoader = webtest.ReloadingTestLoader()40 CPTestRunner = webtest.TerseTestRunner(verbosity=2)41 42 43 def report_coverage(coverage):44 localDir = os.path.dirname(__file__)45 curpath = os.path.normpath(os.path.join(os.getcwd(), localDir))46 basedir = os.path.normpath(os.path.join(curpath, '../'))47 48 coverage.get_ready()49 morfs = [x for x in coverage.cexecuted if x.startswith(basedir.lower())]50 51 total_statements = 052 total_executed = 053 54 print55 print "CODE COVERAGE (this might take a while)",56 for morf in morfs:57 sys.stdout.write(".")58 sys.stdout.flush()59 name = os.path.split(morf)[1]60 try:61 _, statements, _, missing, readable = coverage.analysis2(morf)62 n = len(statements)63 m = n - len(missing)64 total_statements = total_statements + n65 total_executed = total_executed + m66 except KeyboardInterrupt:67 raise68 except:69 pass70 71 pc = 100.072 if total_statements > 0:73 pc = 100.0 * total_executed / total_statements74 75 print ("\nTotal: %s Covered: %s Percent: %2d%%"76 % (total_statements, total_executed, pc))77 78 79 def run_test_suite(moduleNames, server, conf):80 cherrypy.config.update({'global': conf.copy()})81 helper.startServer(server)82 for testmod in moduleNames:83 # Must run each module in a separate suite,84 # because each module uses/overwrites cherrypy globals.85 cherrypy.config.reset()86 cherrypy.config.update({'global': conf.copy()})87 cherrypy._cputil._cpInitDefaultFilters()88 suite = CPTestLoader.loadTestsFromName(testmod)89 90 CPTestRunner.run(suite)91 helper.stopServer()92 38 93 39 testDict = { … … 106 52 } 107 53 54 108 55 def help(): 109 56 print """CherryPy Test Program … … 167 114 168 115 169 def runTests(servers, testList, cover=False, profile=False):116 def main(servers, testList, cover=False, profile=False): 170 117 # Place our current directory's parent (cherrypy/) at the beginning 171 118 # of sys.path, so that all imports are from our current directory. … … 175 122 176 123 if cover: 177 # Start the coverage tool before importing cherrypy, so module-level178 # global statements are covered.124 # Start the coverage tool before importing cherrypy, 125 # so module-level global statements are covered. 179 126 try: 180 127 from coverage import the_coverage as coverage … … 187 134 coverage = None 188 135 189 global cherrypy, helper136 import cherrypy 190 137 print "Python version used to run this test script:", sys.version.split()[0] 191 try:192 import cherrypy193 from cherrypy.test import helper194 except ImportError:195 print "Error: couldn't find CherryPy !"196 os._exit(-1)197 138 print "CherryPy version", cherrypy.__version__ 198 139 print 140 141 from cherrypy.test import helper 199 142 200 143 class NotReadyTest(helper.CPWebCase): … … 205 148 cherrypy.root = Root() 206 149 self.assertRaises(cherrypy.NotReady, self.getPage, "/") 207 CPTestRunner.run(NotReadyTest("testNotReadyError")) 208 209 server_conf = {'server.socketHost': helper.HOST, 210 'server.socketPort': helper.PORT, 211 'server.threadPool': 10, 212 'server.logToScreen': False, 213 'server.environment': "production", 150 helper.CPTestRunner.run(NotReadyTest("testNotReadyError")) 151 152 server_conf = {'global': {'server.socketHost': helper.HOST, 153 'server.socketPort': helper.PORT, 154 'server.threadPool': 10, 155 'server.logToScreen': False, 156 'server.environment': "production", 157 } 214 158 } 215 159 … … 223 167 print 224 168 print "Running testList: Serverless" 225 run_test_suite(testList, None, server_conf)169 helper.run_test_suite(testList, None, server_conf) 226 170 227 171 if 'native' in servers: 228 172 print 229 173 print "Running testList: Native HTTP Server" 230 run_test_suite(testList, "cherrypy._cphttpserver.embedded_server", server_conf)174 helper.run_test_suite(testList, "cherrypy._cphttpserver.embedded_server", server_conf) 231 175 232 176 if 'wsgi' in servers: 233 177 print 234 178 print "Running testList: Native WSGI Server" 235 run_test_suite(testList, "cherrypy._cpwsgi.WSGIServer", server_conf)179 helper.run_test_suite(testList, "cherrypy._cpwsgi.WSGIServer", server_conf) 236 180 237 181 if profile or cover: … … 246 190 if coverage: 247 191 coverage.save() 248 report_coverage(coverage)192 helper.report_coverage(coverage) 249 193 print "run /cherrypy/lib/covercp.py as a script to serve coverage results on port 8080" 250 194 … … 261 205 print argError 262 206 else: 263 runTests(servers, testList, cover, profile)207 main(servers, testList, cover, profile) trunk/cherrypy/test/test_baseurl_filter.py
r471 r474 46 46 }) 47 47 48 import unittest49 48 import helper 50 49 … … 57 56 58 57 if __name__ == '__main__': 59 cherrypy.server.start(initOnly=True) 60 unittest.main() 58 helper.testmain() 61 59 trunk/cherrypy/test/test_cache_filter.py
r471 r474 51 51 52 52 53 import unittest54 53 import helper 55 54 … … 62 61 63 62 if __name__ == '__main__': 64 cherrypy.server.start(initOnly=True) 65 unittest.main() 63 helper.testmain() trunk/cherrypy/test/test_combinedfilters.py
r471 r474 48 48 } 49 49 }) 50 cherrypy.server.start(initOnly=True)51 50 52 import unittest53 51 import helper 54 52 … … 67 65 68 66 if __name__ == '__main__': 69 unittest.main()67 helper.testmain() trunk/cherrypy/test/test_core.py
r471 r474 230 230 }, 231 231 }) 232 cherrypy.server.start(initOnly=True) 233 234 import unittest 232 235 233 import helper 236 234 import os … … 437 435 438 436 if __name__ == '__main__': 439 unittest.main()437 helper.testmain() trunk/cherrypy/test/test_decodingencoding_filter.py
r471 r474 45 45 } 46 46 }) 47 cherrypy.server.start(initOnly=True)48 47 49 48 50 import unittest51 49 import helper 52 50 … … 61 59 62 60 if __name__ == "__main__": 63 unittest.main()61 helper.testmain() trunk/cherrypy/test/test_gzip_filter.py
r471 r474 51 51 }) 52 52 53 cherrypy.server.start(initOnly=True)54 53 55 56 import unittest57 54 import helper 58 55 … … 81 78 82 79 if __name__ == "__main__": 83 unittest.main() 84 80 helper.testmain() trunk/cherrypy/test/test_logdebuginfo_filter.py
r471 r474 48 48 } 49 49 }) 50 cherrypy.server.start(initOnly=True)51 50 52 51 53 import unittest54 52 import helper 55 53 … … 65 63 66 64 if __name__ == "__main__": 67 unittest.main()65 helper.testmain() trunk/cherrypy/test/test_objectmapping.py
r471 r474 99 99 } 100 100 }) 101 cherrypy.server.start(initOnly=True)102 101 103 102 104 import unittest105 103 import helper 106 104 … … 144 142 145 143 if __name__ == "__main__": 146 unittest.main() 147 144 helper.testmain() trunk/cherrypy/test/test_session_filter.py
r471 r474 199 199 pass 200 200 201 cherrypy.server.start(initOnly = True) 202 unittest.main() 201 helper.testmain() trunk/cherrypy/test/test_static_filter.py
r471 r474 48 48 } 49 49 }) 50 cherrypy.server.start(initOnly=True)51 50 52 53 import unittest54 51 import helper 55 52 … … 70 67 71 68 if __name__ == "__main__": 72 unittest.main()69 helper.testmain() trunk/cherrypy/test/test_tutorials.py
r471 r474 180 180 181 181 if __name__ == "__main__": 182 unittest.main() 183 182 helper.testmain() trunk/cherrypy/test/test_virtualhost_filter.py
r471 r474 43 43 }, 44 44 }) 45 cherrypy.server.start(initOnly=True)46 45 47 48 import unittest49 46 import helper 50 47 … … 57 54 58 55 if __name__ == "__main__": 59 unittest.main()56 helper.testmain()

