##// END OF EJS Templates
contrib: refer to RHEL and derivatives instead of CentOS specifically...
contrib: refer to RHEL and derivatives instead of CentOS specifically Differential Revision: https://phab.mercurial-scm.org/D12182

File last commit:

r47960:b0e92313 default
r49613:6387562e stable
Show More
test-doctest.py
177 lines | 5.9 KiB | text/x-python | PythonLexer
Mads Kiilerich
tests: fix readline escape characters in output for test-doctest.py
r7041 # this is hack to make sure no escape characters are inserted into the output
Pulkit Goyal
tests: make test-doctest use absolute_import
r28933
from __future__ import absolute_import
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055 from __future__ import print_function
Pulkit Goyal
tests: make test-doctest use absolute_import
r28933
import doctest
Martin von Zweigbergk
tests: fix test-check-module-imports.t broken by D9150...
r46249 import os
Yuya Nishihara
doctest: normalize b'', u'' and exception output on Python 3...
r34142 import re
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055 import subprocess
Pulkit Goyal
tests: make test-doctest use absolute_import
r28933 import sys
Yuya Nishihara
tests: allow running doctests selectively on Python 3...
r31438
Augie Fackler
formatting: blacken the codebase...
r43346 ispy3 = sys.version_info[0] >= 3
Yuya Nishihara
tests: allow running doctests selectively on Python 3...
r31438
Patrick Mezard
test-doctest: remove TERM env variable only if it's there
r7078 if 'TERM' in os.environ:
Dirkjan Ochtman
clean up trailing spaces
r7184 del os.environ['TERM']
Benoit Boissinot
[extendedchangelog] encode/decode function...
r3232
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
doctest: normalize b'', u'' and exception output on Python 3...
r34142 class py3docchecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
want2 = re.sub(r'''\bu(['"])(.*?)\1''', r'\1\2\1', want) # py2: u''
got2 = re.sub(r'''\bb(['"])(.*?)\1''', r'\1\2\1', got) # py3: b''
# py3: <exc.name>: b'<msg>' -> <name>: <msg>
# <exc.name>: <others> -> <name>: <others>
Augie Fackler
formatting: blacken the codebase...
r43346 got2 = re.sub(
r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''',
r'\1: \3',
got2,
re.MULTILINE,
)
Yuya Nishihara
doctest: normalize b'', u'' and exception output on Python 3...
r34142 got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE)
Augie Fackler
formatting: blacken the codebase...
r43346 return any(
doctest.OutputChecker.check_output(self, w, g, optionflags)
for w, g in [(want, got), (want2, got2)]
)
Yuya Nishihara
doctest: normalize b'', u'' and exception output on Python 3...
r34142
Yuya Nishihara
doctest: drop hack to run py2/3 tests selectively...
r34425 def testmod(name, optionflags=0, testtarget=None):
Mads Kiilerich
tests: make doctest test runner less verbose
r20047 __import__(name)
mod = sys.modules[name]
if testtarget is not None:
mod = getattr(mod, testtarget)
Yuya Nishihara
doctest: normalize b'', u'' and exception output on Python 3...
r34142
# minimal copy of doctest.testmod()
finder = doctest.DocTestFinder()
checker = None
if ispy3:
checker = py3docchecker()
runner = doctest.DocTestRunner(checker=checker, optionflags=optionflags)
for test in finder.find(mod, name):
runner.run(test)
runner.summarize()
Sune Foldager
ui: add configint function and tests
r14171
Augie Fackler
formatting: blacken the codebase...
r43346
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055 DONT_RUN = []
# Exceptions to the defaults for a given detected module. The value for each
# module name is a list of dicts that specify the kwargs to pass to testmod.
# testmod is called once per item in the list, so an empty list will cause the
# module to not be tested.
testmod_arg_overrides = {
'i18n.check-translation': DONT_RUN, # may require extra installation
'mercurial.dagparser': [{'optionflags': doctest.NORMALIZE_WHITESPACE}],
'mercurial.keepalive': DONT_RUN, # >>> is an example, not a doctest
'mercurial.posix': DONT_RUN, # run by mercurial.platform
'mercurial.statprof': DONT_RUN, # >>> is an example, not a doctest
'mercurial.util': [{}, {'testtarget': 'platform'}], # run twice!
'mercurial.windows': DONT_RUN, # run by mercurial.platform
'tests.test-url': [{'optionflags': doctest.NORMALIZE_WHITESPACE}],
}
Gregory Szorc
tests: perform grep manually in test-doctest.py...
r45144 fileset = 'set:(**.py)'
cwd = os.path.dirname(os.environ["TESTDIR"])
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055
Joerg Sonnenberger
tests: skip doctests if not running from a hg repo...
r46209 if not os.path.isdir(os.path.join(cwd, ".hg")):
sys.exit(0)
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055 files = subprocess.check_output(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 "hg files --print0 \"%s\"" % fileset,
shell=True,
cwd=cwd,
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055 ).split(b'\0')
Gregory Szorc
tests: perform grep manually in test-doctest.py...
r45144 if sys.version_info[0] >= 3:
cwd = os.fsencode(cwd)
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055 mods_tested = set()
for f in files:
if not f:
continue
Gregory Szorc
tests: perform grep manually in test-doctest.py...
r45144 with open(os.path.join(cwd, f), "rb") as fh:
if not re.search(br'\n\s*>>>', fh.read()):
continue
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055 if ispy3:
f = f.decode()
modname = f.replace('.py', '').replace('\\', '.').replace('/', '.')
# Third-party modules aren't our responsibility to test, and the modules in
# contrib generally do not have doctests in a good state, plus they're hard
# to import if this test is running with py2, so we just skip both for now.
if modname.startswith('mercurial.thirdparty.') or modname.startswith(
'contrib.'
):
continue
for kwargs in testmod_arg_overrides.get(modname, [{}]):
mods_tested.add((modname, '%r' % (kwargs,)))
if modname.startswith('tests.'):
# On py2, we can't import from tests.foo, but it works on both py2
# and py3 with the way that PYTHONPATH is setup to import without
# the 'tests.' prefix, so we do that.
modname = modname[len('tests.') :]
testmod(modname, **kwargs)
Kyle Lippincott
tests: make test-doctest.t module list match reality...
r45054
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055 # Meta-test: let's make sure that we actually ran what we expected to, above.
# Each item in the set is a 2-tuple of module name and stringified kwargs passed
# to testmod.
expected_mods_tested = set(
[
('hgext.convert.convcmd', '{}'),
('hgext.convert.cvsps', '{}'),
('hgext.convert.filemap', '{}'),
('hgext.convert.p4', '{}'),
('hgext.convert.subversion', '{}'),
('hgext.fix', '{}'),
('hgext.mq', '{}'),
('mercurial.changelog', '{}'),
('mercurial.cmdutil', '{}'),
('mercurial.color', '{}'),
('mercurial.dagparser', "{'optionflags': 4}"),
('mercurial.encoding', '{}'),
('mercurial.fancyopts', '{}'),
('mercurial.formatter', '{}'),
('mercurial.hg', '{}'),
('mercurial.hgweb.hgwebdir_mod', '{}'),
('mercurial.match', '{}'),
('mercurial.mdiff', '{}'),
('mercurial.minirst', '{}'),
('mercurial.parser', '{}'),
('mercurial.patch', '{}'),
('mercurial.pathutil', '{}'),
('mercurial.pycompat', '{}'),
('mercurial.revlogutils.deltas', '{}'),
('mercurial.revset', '{}'),
('mercurial.revsetlang', '{}'),
('mercurial.simplemerge', '{}'),
('mercurial.smartset', '{}'),
('mercurial.store', '{}'),
('mercurial.subrepo', '{}'),
('mercurial.templater', '{}'),
('mercurial.ui', '{}'),
('mercurial.util', "{'testtarget': 'platform'}"),
('mercurial.util', '{}'),
('mercurial.utils.dateutil', '{}'),
('mercurial.utils.stringutil', '{}'),
urlutil: extract `url` related code from `util` into the new module...
r47669 ('mercurial.utils.urlutil', '{}'),
Kyle Lippincott
tests: make test-doctest.t automatically find files to run tests on...
r45055 ('tests.drawdag', '{}'),
('tests.test-run-tests', '{}'),
('tests.test-url', "{'optionflags': 4}"),
]
)
unexpectedly_run = mods_tested.difference(expected_mods_tested)
not_run = expected_mods_tested.difference(mods_tested)
if unexpectedly_run:
print('Unexpectedly ran (probably need to add to list):')
for r in sorted(unexpectedly_run):
print(' %r' % (r,))
if not_run:
print('Expected to run, but was not run (doctest removed?):')
for r in sorted(not_run):
print(' %r' % (r,))