Write untested_url_report.txt.

This commit is contained in:
Steve Howell 2016-07-27 17:40:04 -07:00 committed by Tim Abbott
parent 8b13530712
commit 2a37dafcbb
2 changed files with 28 additions and 4 deletions

View File

@ -225,17 +225,41 @@ def instrument_url(f):
return result
return wrapper
def write_instrumentation_report():
def write_instrumentation_reports():
# type: () -> None
if INSTRUMENTING:
calls = INSTRUMENTED_CALLS
var_dir = 'var' # TODO make sure path is robust here
fn = os.path.join(var_dir, 'url_coverage.txt')
with open(fn, 'w') as f:
for call in INSTRUMENTED_CALLS:
for call in calls:
line = ujson.dumps(call)
f.write(line + '\n')
print('URL coverage report is in %s' % (fn,))
print('Try running: ./tools/analyze-url-coverage')
# Find our untested urls.
from zproject.urls import urlpatterns
untested_patterns = []
for pattern in urlpatterns:
for call in calls:
url = call['url']
if url.startswith('/'):
url = url[1:]
if pattern.regex.match(url):
break
else:
untested_patterns.append(pattern.regex.pattern)
fn = os.path.join(var_dir, 'untested_url_report.txt')
with open(fn, 'w') as f:
f.write('untested urls\n')
for untested_pattern in sorted(untested_patterns):
f.write(' %s\n' % (untested_pattern,))
print('Untested-url report is in %s' % (fn,))
class AuthedTestCase(TestCase):
'''
WRAPPER_COMMENT:

View File

@ -9,7 +9,7 @@ from django.test.signals import template_rendered
from zerver.lib.cache import bounce_key_prefix_for_testing
from zerver.lib.sqlalchemy_utils import get_sqlalchemy_connection
from zerver.lib.test_helpers import (
get_all_templates, write_instrumentation_report,
get_all_templates, write_instrumentation_reports,
)
import os
@ -206,5 +206,5 @@ class Runner(DiscoverRunner):
failed = self.run_suite(suite, fatal_errors=kwargs.get('fatal_errors'))
self.teardown_test_environment()
if not failed:
write_instrumentation_report()
write_instrumentation_reports()
return failed