test-doctest.py
94 lines
| 2.8 KiB
| text/x-python
|
PythonLexer
/ tests / test-doctest.py
|
r7041 | # this is hack to make sure no escape characters are inserted into the output | ||
|
r28933 | |||
from __future__ import absolute_import | ||||
import doctest | ||||
import os | ||||
|
r34142 | import re | ||
|
r28933 | import sys | ||
|
r31438 | |||
|
r43346 | ispy3 = sys.version_info[0] >= 3 | ||
|
r31438 | |||
|
r7078 | if 'TERM' in os.environ: | ||
|
r7184 | del os.environ['TERM'] | ||
|
r3232 | |||
|
r43346 | |||
|
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> | ||||
|
r43346 | got2 = re.sub( | ||
r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''', | ||||
r'\1: \3', | ||||
got2, | ||||
re.MULTILINE, | ||||
) | ||||
|
r34142 | got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE) | ||
|
r43346 | return any( | ||
doctest.OutputChecker.check_output(self, w, g, optionflags) | ||||
for w, g in [(want, got), (want2, got2)] | ||||
) | ||||
|
r34142 | |||
|
r34425 | def testmod(name, optionflags=0, testtarget=None): | ||
|
r20047 | __import__(name) | ||
mod = sys.modules[name] | ||||
if testtarget is not None: | ||||
mod = getattr(mod, testtarget) | ||||
|
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() | ||||
|
r14171 | |||
|
r43346 | |||
|
r20047 | testmod('mercurial.changelog') | ||
|
r36528 | testmod('mercurial.cmdutil') | ||
|
r31518 | testmod('mercurial.color') | ||
|
r31481 | testmod('mercurial.config') | ||
|
r34209 | testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE) | ||
|
r34215 | testmod('mercurial.encoding') | ||
|
r35179 | testmod('mercurial.fancyopts') | ||
|
r34257 | testmod('mercurial.formatter') | ||
|
r20799 | testmod('mercurial.hg') | ||
|
r34354 | testmod('mercurial.hgweb.hgwebdir_mod') | ||
|
r20047 | testmod('mercurial.match') | ||
|
r31808 | testmod('mercurial.mdiff') | ||
|
r20047 | testmod('mercurial.minirst') | ||
|
r45054 | testmod('mercurial.parser') | ||
|
r34254 | testmod('mercurial.patch') | ||
|
r34255 | testmod('mercurial.pathutil') | ||
|
r34143 | testmod('mercurial.pycompat') | ||
|
r40676 | testmod('mercurial.revlogutils.deltas') | ||
r41395 | testmod('mercurial.revset') | |||
|
r31024 | testmod('mercurial.revsetlang') | ||
|
r45054 | testmod('mercurial.simplemerge') | ||
|
r30881 | testmod('mercurial.smartset') | ||
|
r34212 | testmod('mercurial.store') | ||
|
r20840 | testmod('mercurial.subrepo') | ||
|
r25783 | testmod('mercurial.templater') | ||
|
r34205 | testmod('mercurial.ui') | ||
|
r34358 | testmod('mercurial.util') | ||
|
r45054 | testmod('mercurial.util', testtarget='platform') # windows.py or posix.py | ||
|
r44219 | testmod('mercurial.utils.dateutil') | ||
|
r37101 | testmod('mercurial.utils.stringutil') | ||
|
r34355 | testmod('hgext.convert.convcmd') | ||
|
r20047 | testmod('hgext.convert.cvsps') | ||
|
r20048 | testmod('hgext.convert.filemap') | ||
|
r25788 | testmod('hgext.convert.p4') | ||
|
r20419 | testmod('hgext.convert.subversion') | ||
|
r37200 | testmod('hgext.fix') | ||
|
r22546 | testmod('hgext.mq') | ||
|
r34203 | # Helper scripts in tests/ that have doctests: | ||
testmod('drawdag') | ||||
|
r45054 | testmod('test-run-tests') | ||
# Disabled since it requires extra modules that might not be installed. | ||||
# testmod('i18n.check-translation') | ||||