test-doctest.py
80 lines
| 2.9 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 | |||
ispy3 = (sys.version_info[0] >= 3) | ||||
|
r7078 | if 'TERM' in os.environ: | ||
|
r7184 | del os.environ['TERM'] | ||
|
r3232 | |||
|
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> | ||||
got2 = re.sub(r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''', r'\1: \3', | ||||
got2, re.MULTILINE) | ||||
got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE) | ||||
return any(doctest.OutputChecker.check_output(self, w, g, optionflags) | ||||
for w, g in [(want, got), (want2, got2)]) | ||||
|
r31438 | # TODO: migrate doctests to py3 and enable them on both versions | ||
|
r34143 | def testmod(name, optionflags=0, testtarget=None, py2=True, py3=True): | ||
|
r31438 | if not (not ispy3 and py2 or ispy3 and py3): | ||
return | ||||
|
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 | |||
|
r27432 | testmod('mercurial.changegroup') | ||
|
r20047 | testmod('mercurial.changelog') | ||
|
r31518 | testmod('mercurial.color') | ||
|
r31481 | testmod('mercurial.config') | ||
|
r32485 | testmod('mercurial.context') | ||
|
r34143 | testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE, | ||
py3=False) # py3: use of str() | ||||
|
r20047 | testmod('mercurial.dispatch') | ||
|
r34143 | testmod('mercurial.encoding', py3=False) # py3: multiple encoding issues | ||
testmod('mercurial.formatter', py3=False) # py3: write bytes to stdout | ||||
|
r20799 | testmod('mercurial.hg') | ||
|
r34143 | testmod('mercurial.hgweb.hgwebdir_mod', py3=False) # py3: repr(bytes) ? | ||
|
r20047 | testmod('mercurial.match') | ||
|
r31808 | testmod('mercurial.mdiff') | ||
|
r20047 | testmod('mercurial.minirst') | ||
|
r34143 | testmod('mercurial.patch', py3=False) # py3: bytes[n], etc. ? | ||
testmod('mercurial.pathutil', py3=False) # py3: os.sep | ||||
|
r25306 | testmod('mercurial.parser') | ||
|
r34143 | testmod('mercurial.pycompat') | ||
|
r31024 | testmod('mercurial.revsetlang') | ||
|
r30881 | testmod('mercurial.smartset') | ||
|
r34143 | testmod('mercurial.store', py3=False) # py3: bytes[n] | ||
|
r20840 | testmod('mercurial.subrepo') | ||
|
r20047 | testmod('mercurial.templatefilters') | ||
|
r25783 | testmod('mercurial.templater') | ||
|
r34143 | testmod('mercurial.ui', py3=False) # py3: __name__ | ||
|
r20047 | testmod('mercurial.url') | ||
|
r34143 | testmod('mercurial.util', py3=False) # py3: multiple bytes/unicode issues | ||
|
r20047 | testmod('mercurial.util', testtarget='platform') | ||
|
r34143 | testmod('hgext.convert.convcmd', py3=False) # py3: use of str() ? | ||
|
r20047 | testmod('hgext.convert.cvsps') | ||
|
r20048 | testmod('hgext.convert.filemap') | ||
|
r25788 | testmod('hgext.convert.p4') | ||
|
r20419 | testmod('hgext.convert.subversion') | ||
|
r22546 | testmod('hgext.mq') | ||