test-doctest.py
80 lines
| 2.6 KiB
| text/x-python
|
PythonLexer
/ tests / test-doctest.py
Mads Kiilerich
|
r7041 | # this is hack to make sure no escape characters are inserted into the output | ||
Pulkit Goyal
|
r28933 | |||
from __future__ import absolute_import | ||||
import doctest | ||||
import os | ||||
Yuya Nishihara
|
r34142 | import re | ||
Pulkit Goyal
|
r28933 | import sys | ||
Yuya Nishihara
|
r31438 | |||
ispy3 = (sys.version_info[0] >= 3) | ||||
Patrick Mezard
|
r7078 | if 'TERM' in os.environ: | ||
Dirkjan Ochtman
|
r7184 | del os.environ['TERM'] | ||
Benoit Boissinot
|
r3232 | |||
Yuya Nishihara
|
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)]) | ||||
Yuya Nishihara
|
r34425 | def testmod(name, optionflags=0, testtarget=None): | ||
Mads Kiilerich
|
r20047 | __import__(name) | ||
mod = sys.modules[name] | ||||
if testtarget is not None: | ||||
mod = getattr(mod, testtarget) | ||||
Yuya Nishihara
|
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
|
r14171 | |||
Augie Fackler
|
r27432 | testmod('mercurial.changegroup') | ||
Mads Kiilerich
|
r20047 | testmod('mercurial.changelog') | ||
Yuya Nishihara
|
r36528 | testmod('mercurial.cmdutil') | ||
Yuya Nishihara
|
r31518 | testmod('mercurial.color') | ||
Jun Wu
|
r31481 | testmod('mercurial.config') | ||
Siddharth Agarwal
|
r32485 | testmod('mercurial.context') | ||
Yuya Nishihara
|
r34209 | testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE) | ||
Mads Kiilerich
|
r20047 | testmod('mercurial.dispatch') | ||
Yuya Nishihara
|
r34215 | testmod('mercurial.encoding') | ||
Yuya Nishihara
|
r35179 | testmod('mercurial.fancyopts') | ||
Yuya Nishihara
|
r34257 | testmod('mercurial.formatter') | ||
Yuya Nishihara
|
r20799 | testmod('mercurial.hg') | ||
Yuya Nishihara
|
r34354 | testmod('mercurial.hgweb.hgwebdir_mod') | ||
Mads Kiilerich
|
r20047 | testmod('mercurial.match') | ||
Denis Laxalde
|
r31808 | testmod('mercurial.mdiff') | ||
Mads Kiilerich
|
r20047 | testmod('mercurial.minirst') | ||
Yuya Nishihara
|
r34254 | testmod('mercurial.patch') | ||
Yuya Nishihara
|
r34255 | testmod('mercurial.pathutil') | ||
Yuya Nishihara
|
r25306 | testmod('mercurial.parser') | ||
Yuya Nishihara
|
r34143 | testmod('mercurial.pycompat') | ||
Yuya Nishihara
|
r31024 | testmod('mercurial.revsetlang') | ||
Yuya Nishihara
|
r30881 | testmod('mercurial.smartset') | ||
Yuya Nishihara
|
r34212 | testmod('mercurial.store') | ||
Siddharth Agarwal
|
r20840 | testmod('mercurial.subrepo') | ||
Mads Kiilerich
|
r20047 | testmod('mercurial.templatefilters') | ||
Yuya Nishihara
|
r25783 | testmod('mercurial.templater') | ||
Yuya Nishihara
|
r34205 | testmod('mercurial.ui') | ||
Mads Kiilerich
|
r20047 | testmod('mercurial.url') | ||
Yuya Nishihara
|
r34358 | testmod('mercurial.util') | ||
Mads Kiilerich
|
r20047 | testmod('mercurial.util', testtarget='platform') | ||
Yuya Nishihara
|
r34355 | testmod('hgext.convert.convcmd') | ||
Mads Kiilerich
|
r20047 | testmod('hgext.convert.cvsps') | ||
Mads Kiilerich
|
r20048 | testmod('hgext.convert.filemap') | ||
Eugene Baranov
|
r25788 | testmod('hgext.convert.p4') | ||
Mads Kiilerich
|
r20419 | testmod('hgext.convert.subversion') | ||
Mads Kiilerich
|
r22546 | testmod('hgext.mq') | ||
Augie Fackler
|
r34203 | # Helper scripts in tests/ that have doctests: | ||
testmod('drawdag') | ||||