##// END OF EJS Templates
run-tests: mechanism to report exceptions during test execution...
run-tests: mechanism to report exceptions during test execution Sometimes when running tests you introduce a ton of exceptions. The most extreme example of this is running Mercurial with Python 3, which currently spews thousands of exceptions when running the test harness. This commit adds an opt-in feature to run-tests.py to aggregate exceptions encountered by `hg` when running tests. When --exceptions is used, the test harness enables the "logexceptions" extension in the test environment. This extension wraps the Mercurial function to handle exceptions and writes information about the exception to a random filename in a directory defined by the test harness via an environment variable. At the end of the test harness, these files are parsed, aggregated, and a list of all unique Mercurial frames triggering exceptions is printed in order of frequency. This feature is intended to aid Python 3 development. I've only really tested it on Python 3. There is no shortage of improvements that could be made. e.g. we could write a separate file containing the exception report - maybe even an HTML report. We also don't capture which tests demonstrate the exceptions, so there's no turnkey way to test whether a code change made an exception disappear. Perfect is the enemy of good. I think the current patch is useful enough to land. Whoever uses it can send patches to imprve its usefulness. Differential Revision: https://phab.mercurial-scm.org/D1477

File last commit:

r32291:bd872f64 default
r35191:bd8875b6 default
Show More
check-perf-code.py
79 lines | 2.5 KiB | text/x-python | PythonLexer
/ tests / check-perf-code.py
FUJIWARA Katsunori
tests: introduce check-perf-code.py to add extra checks on perf.py...
r29570 #!/usr/bin/env python
#
# check-perf-code - (historical) portability checker for contrib/perf.py
from __future__ import absolute_import
import os
import sys
# write static check patterns here
perfpypats = [
[
FUJIWARA Katsunori
perf: get subsettable from appropriate module for Mercurial earlier than 2.9...
r30144 (r'(branchmap|repoview)\.subsettable',
"use getbranchmapsubsettable() for early Mercurial"),
FUJIWARA Katsunori
perf: add functions to get vfs-like object for Mercurial earlier than 2.3...
r30146 (r'\.(vfs|svfs|opener|sopener)',
"use getvfs()/getsvfs() for early Mercurial"),
FUJIWARA Katsunori
perf: replace ui.configint() by getint() for Mercurial earlier than 1.9...
r30149 (r'ui\.configint',
"use getint() instead of ui.configint() for early Mercurial"),
FUJIWARA Katsunori
tests: introduce check-perf-code.py to add extra checks on perf.py...
r29570 ],
# warnings
[
]
]
FUJIWARA Katsunori
tests: check importing modules in perf.py for historical portability...
r29571 def modulewhitelist(names):
replacement = [('.py', ''), ('.c', ''), # trim suffix
('mercurial%s' % (os.sep), ''), # trim "mercurial/" path
]
Martin von Zweigbergk
cleanup: use set literals...
r32291 ignored = {'__init__'}
FUJIWARA Katsunori
tests: check importing modules in perf.py for historical portability...
r29571 modules = {}
# convert from file name to module name, and count # of appearances
for name in names:
name = name.strip()
for old, new in replacement:
name = name.replace(old, new)
if name not in ignored:
modules[name] = modules.get(name, 0) + 1
# list up module names, which appear multiple times
whitelist = []
for name, count in modules.items():
if count > 1:
whitelist.append(name)
return whitelist
FUJIWARA Katsunori
tests: introduce check-perf-code.py to add extra checks on perf.py...
r29570 if __name__ == "__main__":
FUJIWARA Katsunori
tests: check importing modules in perf.py for historical portability...
r29571 # in this case, it is assumed that result of "hg files" at
# multiple revisions is given via stdin
whitelist = modulewhitelist(sys.stdin)
assert whitelist, "module whitelist is empty"
# build up module whitelist check from file names given at runtime
perfpypats[0].append(
# this matching pattern assumes importing modules from
# "mercurial" package in the current style below, for simplicity
#
# from mercurial import (
# foo,
# bar,
# baz
# )
((r'from mercurial import [(][a-z0-9, \n#]*\n(?! *%s,|^[ #]*\n|[)])'
% ',| *'.join(whitelist)),
"import newer module separately in try clause for early Mercurial"
))
FUJIWARA Katsunori
tests: introduce check-perf-code.py to add extra checks on perf.py...
r29570 # import contrib/check-code.py as checkcode
assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script"
contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib')
sys.path.insert(0, contribpath)
checkcode = __import__('check-code')
# register perf.py specific entry with "checks" in check-code.py
checkcode.checks.append(('perf.py', r'contrib/perf.py$', '',
checkcode.pyfilters, perfpypats))
sys.exit(checkcode.main())