| | 127 | def report_coverage(coverage): |
|---|
| | 128 | localDir = os.path.dirname(__file__) |
|---|
| | 129 | curpath = os.path.normpath(os.path.join(os.getcwd(), localDir)) |
|---|
| | 130 | basedir = os.path.normpath(os.path.join(curpath, '../')) |
|---|
| | 131 | |
|---|
| | 132 | coverage.get_ready() |
|---|
| | 133 | morfs = [x for x in coverage.cexecuted if x.startswith(basedir.lower())] |
|---|
| | 134 | |
|---|
| | 135 | total_statements = 0 |
|---|
| | 136 | total_executed = 0 |
|---|
| | 137 | |
|---|
| | 138 | print |
|---|
| | 139 | print "CODE COVERAGE (this might take a while)", |
|---|
| | 140 | for morf in morfs: |
|---|
| | 141 | sys.stdout.write(".") |
|---|
| | 142 | sys.stdout.flush() |
|---|
| | 143 | name = os.path.split(morf)[1] |
|---|
| | 144 | try: |
|---|
| | 145 | _, statements, _, missing, readable = coverage.analysis2(morf) |
|---|
| | 146 | n = len(statements) |
|---|
| | 147 | m = n - len(missing) |
|---|
| | 148 | total_statements = total_statements + n |
|---|
| | 149 | total_executed = total_executed + m |
|---|
| | 150 | except KeyboardInterrupt: |
|---|
| | 151 | raise |
|---|
| | 152 | except: |
|---|
| | 153 | pass |
|---|
| | 154 | |
|---|
| | 155 | pc = 100.0 |
|---|
| | 156 | if total_statements > 0: |
|---|
| | 157 | pc = 100.0 * total_executed / total_statements |
|---|
| | 158 | |
|---|
| | 159 | print ("\nTotal: %s Covered: %s Percent: %2d%%" |
|---|
| | 160 | % (total_statements, total_executed, pc)) |
|---|
| | 161 | |
|---|
| | 162 | |
|---|
| | 163 | def run_test_suite(moduleNames, server, conf): |
|---|
| | 164 | cherrypy.config.update({'global': conf.copy()}) |
|---|
| | 165 | helper.startServer(server) |
|---|
| | 166 | for testmod in moduleNames: |
|---|
| | 167 | # Must run each module in a separate suite, |
|---|
| | 168 | # because each module uses/overwrites cherrypy globals. |
|---|
| | 169 | cherrypy.config.reset() |
|---|
| | 170 | cherrypy.config.update({'global': conf.copy()}) |
|---|
| | 171 | cherrypy._cputil._cpInitDefaultFilters() |
|---|
| | 172 | suite = CPTestLoader.loadTestsFromName(testmod) |
|---|
| | 173 | CPTestRunner(verbosity=2).run(suite) |
|---|
| | 174 | helper.stopServer() |
|---|
| | 175 | |
|---|
| | 176 | |
|---|
| 175 | | for name, server in [("Serverless", None), |
|---|
| 176 | | ("Native HTTP Server", "cherrypy._cphttpserver.embedded_server"), |
|---|
| 177 | | ("Native WSGI Server", "cherrypy._cpwsgi.WSGIServer"), |
|---|
| 178 | | ]: |
|---|
| 179 | | print |
|---|
| 180 | | print "Running tests:", name |
|---|
| 181 | | |
|---|
| 182 | | cherrypy.config.update({'global': server_conf.copy()}) |
|---|
| 183 | | helper.startServer(server) |
|---|
| 184 | | for testmod in testList: |
|---|
| 185 | | # Must run each module in a separate suite, |
|---|
| 186 | | # because each module uses/overwrites cherrypy globals. |
|---|
| 187 | | cherrypy.config.reset() |
|---|
| 188 | | cherrypy.config.update({'global': server_conf.copy()}) |
|---|
| 189 | | cherrypy._cputil._cpInitDefaultFilters() |
|---|
| 190 | | suite = CPTestLoader.loadTestsFromName(testmod) |
|---|
| 191 | | CPTestRunner(verbosity=2).run(suite) |
|---|
| 192 | | helper.stopServer() |
|---|
| 193 | | |
|---|
| | 233 | print |
|---|
| | 234 | print "Running tests: Serverless" |
|---|
| | 235 | cherrypy.codecoverage = True |
|---|
| | 236 | run_test_suite(testList, None, server_conf) |
|---|
| | 237 | cherrypy.codecoverage = False |
|---|
| | 238 | |
|---|
| | 239 | print |
|---|
| | 240 | print "Running tests: Native HTTP Server" |
|---|
| | 241 | run_test_suite(testList, "cherrypy._cphttpserver.embedded_server", server_conf) |
|---|
| | 242 | |
|---|
| | 243 | print |
|---|
| | 244 | print "Running tests: Native WSGI Server" |
|---|
| | 245 | server_conf['profiling.on'] = True |
|---|
| | 246 | run_test_suite(testList, "cherrypy._cpwsgi.WSGIServer", server_conf) |
|---|
| | 247 | del server_conf['profiling.on'] |
|---|
| | 248 | |
|---|
| | 249 | if coverage: |
|---|
| | 250 | report_coverage(coverage) |
|---|
| | 251 | print "run /cherrypy/lib/covercp.py as a script to serve coverage results on port 8080" |
|---|
| | 252 | |
|---|
| | 253 | print "run /cherrypy/lib/profiler.py as a script to serve profiling results on port 8080" |
|---|
| | 254 | |
|---|
| | 255 | print |
|---|