mirror of https://github.com/zulip/zulip.git
coverage: bring test_helpers.py to 100% coverage.
This commit is contained in:
parent
546fb9199d
commit
e7ff3415ab
|
@ -54,6 +54,7 @@ target_fully_covered = {path for target in [
|
||||||
'zerver/lib/notifications.py',
|
'zerver/lib/notifications.py',
|
||||||
'zerver/lib/push_notifications.py',
|
'zerver/lib/push_notifications.py',
|
||||||
'zerver/lib/request.py',
|
'zerver/lib/request.py',
|
||||||
|
'zerver/lib/test_helpers.py',
|
||||||
'zerver/lib/test_classes.py',
|
'zerver/lib/test_classes.py',
|
||||||
'zerver/lib/upload.py',
|
'zerver/lib/upload.py',
|
||||||
'zerver/lib/validator.py',
|
'zerver/lib/validator.py',
|
||||||
|
|
|
@ -109,7 +109,7 @@ def simulated_empty_cache():
|
||||||
cache_queries.append(('get', key, cache_name))
|
cache_queries.append(('get', key, cache_name))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def my_cache_get_many(keys, cache_name=None):
|
def my_cache_get_many(keys, cache_name=None): # nocoverage -- simulated code doesn't use this
|
||||||
# type: (List[Text], Optional[str]) -> Dict[Text, Any]
|
# type: (List[Text], Optional[str]) -> Dict[Text, Any]
|
||||||
cache_queries.append(('getmany', keys, cache_name))
|
cache_queries.append(('getmany', keys, cache_name))
|
||||||
return {}
|
return {}
|
||||||
|
@ -158,7 +158,7 @@ def queries_captured(include_savepoints=False):
|
||||||
|
|
||||||
def cursor_executemany(self, sql, params=()):
|
def cursor_executemany(self, sql, params=()):
|
||||||
# type: (TimeTrackingCursor, NonBinaryStr, Iterable[Any]) -> None
|
# type: (TimeTrackingCursor, NonBinaryStr, Iterable[Any]) -> None
|
||||||
return wrapper_execute(self, super(TimeTrackingCursor, self).executemany, sql, params) # type: ignore # https://github.com/JukkaL/mypy/issues/1167
|
return wrapper_execute(self, super(TimeTrackingCursor, self).executemany, sql, params) # type: ignore # https://github.com/JukkaL/mypy/issues/1167 # nocoverage -- doesn't actually get used in tests
|
||||||
TimeTrackingCursor.executemany = cursor_executemany # type: ignore # https://github.com/JukkaL/mypy/issues/1167
|
TimeTrackingCursor.executemany = cursor_executemany # type: ignore # https://github.com/JukkaL/mypy/issues/1167
|
||||||
|
|
||||||
yield queries
|
yield queries
|
||||||
|
@ -200,7 +200,7 @@ def find_key_by_email(address):
|
||||||
for message in reversed(outbox):
|
for message in reversed(outbox):
|
||||||
if address in message.to:
|
if address in message.to:
|
||||||
return key_regex.search(message.body).groups()[0]
|
return key_regex.search(message.body).groups()[0]
|
||||||
return None
|
return None # nocoverage -- in theory a test might want this case, but none do
|
||||||
|
|
||||||
def find_pattern_in_email(address, pattern):
|
def find_pattern_in_email(address, pattern):
|
||||||
# type: (Text, Text) -> Optional[Text]
|
# type: (Text, Text) -> Optional[Text]
|
||||||
|
@ -209,7 +209,7 @@ def find_pattern_in_email(address, pattern):
|
||||||
for message in reversed(outbox):
|
for message in reversed(outbox):
|
||||||
if address in message.to:
|
if address in message.to:
|
||||||
return key_regex.search(message.body).group(0)
|
return key_regex.search(message.body).group(0)
|
||||||
return None
|
return None # nocoverage -- in theory a test might want this case, but none do
|
||||||
|
|
||||||
def message_ids(result):
|
def message_ids(result):
|
||||||
# type: (Dict[str, Any]) -> Set[int]
|
# type: (Dict[str, Any]) -> Set[int]
|
||||||
|
@ -295,18 +295,13 @@ INSTRUMENTED_CALLS = [] # type: List[Dict[str, Any]]
|
||||||
|
|
||||||
UrlFuncT = Callable[..., HttpResponse] # TODO: make more specific
|
UrlFuncT = Callable[..., HttpResponse] # TODO: make more specific
|
||||||
|
|
||||||
def process_instrumented_calls(func):
|
|
||||||
# type: (Callable) -> None
|
|
||||||
for call in INSTRUMENTED_CALLS:
|
|
||||||
func(call)
|
|
||||||
|
|
||||||
def append_instrumentation_data(data):
|
def append_instrumentation_data(data):
|
||||||
# type: (Dict[str, Any]) -> None
|
# type: (Dict[str, Any]) -> None
|
||||||
INSTRUMENTED_CALLS.append(data)
|
INSTRUMENTED_CALLS.append(data)
|
||||||
|
|
||||||
def instrument_url(f):
|
def instrument_url(f):
|
||||||
# type: (UrlFuncT) -> UrlFuncT
|
# type: (UrlFuncT) -> UrlFuncT
|
||||||
if not INSTRUMENTING:
|
if not INSTRUMENTING: # nocoverage -- option is always enabled; should we remove?
|
||||||
return f
|
return f
|
||||||
else:
|
else:
|
||||||
def wrapper(self, url, info={}, **kwargs):
|
def wrapper(self, url, info={}, **kwargs):
|
||||||
|
@ -367,7 +362,7 @@ def write_instrumentation_reports(full_suite):
|
||||||
# type: (Any, List[str]) -> None
|
# type: (Any, List[str]) -> None
|
||||||
|
|
||||||
if isinstance(pattern, type(LocaleRegexURLResolver)):
|
if isinstance(pattern, type(LocaleRegexURLResolver)):
|
||||||
return
|
return # nocoverage -- shouldn't actually happen
|
||||||
|
|
||||||
if hasattr(pattern, 'url_patterns'):
|
if hasattr(pattern, 'url_patterns'):
|
||||||
return
|
return
|
||||||
|
@ -410,7 +405,7 @@ def write_instrumentation_reports(full_suite):
|
||||||
try:
|
try:
|
||||||
line = ujson.dumps(call)
|
line = ujson.dumps(call)
|
||||||
f.write(line + '\n')
|
f.write(line + '\n')
|
||||||
except OverflowError:
|
except OverflowError: # nocoverage -- test suite error handling
|
||||||
print('''
|
print('''
|
||||||
A JSON overflow error was encountered while
|
A JSON overflow error was encountered while
|
||||||
producing the URL coverage report. Sometimes
|
producing the URL coverage report. Sometimes
|
||||||
|
@ -424,7 +419,7 @@ def write_instrumentation_reports(full_suite):
|
||||||
print('INFO: URL coverage report is in %s' % (fn,))
|
print('INFO: URL coverage report is in %s' % (fn,))
|
||||||
print('INFO: Try running: ./tools/create-test-api-docs')
|
print('INFO: Try running: ./tools/create-test-api-docs')
|
||||||
|
|
||||||
if full_suite and len(untested_patterns):
|
if full_suite and len(untested_patterns): # nocoverage -- test suite error handling
|
||||||
print("\nERROR: Some URLs are untested! Here's the list of untested URLs:")
|
print("\nERROR: Some URLs are untested! Here's the list of untested URLs:")
|
||||||
for untested_pattern in sorted(untested_patterns):
|
for untested_pattern in sorted(untested_patterns):
|
||||||
print(" %s" % (untested_pattern,))
|
print(" %s" % (untested_pattern,))
|
||||||
|
|
Loading…
Reference in New Issue