Show More
@@ -1,79 +1,80 b'' | |||
|
1 | 1 | # this is hack to make sure no escape characters are inserted into the output |
|
2 | 2 | |
|
3 | 3 | from __future__ import absolute_import |
|
4 | 4 | |
|
5 | 5 | import doctest |
|
6 | 6 | import os |
|
7 | 7 | import re |
|
8 | 8 | import sys |
|
9 | 9 | |
|
10 | 10 | ispy3 = (sys.version_info[0] >= 3) |
|
11 | 11 | |
|
12 | 12 | if 'TERM' in os.environ: |
|
13 | 13 | del os.environ['TERM'] |
|
14 | 14 | |
|
15 | 15 | class py3docchecker(doctest.OutputChecker): |
|
16 | 16 | def check_output(self, want, got, optionflags): |
|
17 | 17 | want2 = re.sub(r'''\bu(['"])(.*?)\1''', r'\1\2\1', want) # py2: u'' |
|
18 | 18 | got2 = re.sub(r'''\bb(['"])(.*?)\1''', r'\1\2\1', got) # py3: b'' |
|
19 | 19 | # py3: <exc.name>: b'<msg>' -> <name>: <msg> |
|
20 | 20 | # <exc.name>: <others> -> <name>: <others> |
|
21 | 21 | got2 = re.sub(r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''', r'\1: \3', |
|
22 | 22 | got2, re.MULTILINE) |
|
23 | 23 | got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE) |
|
24 | 24 | return any(doctest.OutputChecker.check_output(self, w, g, optionflags) |
|
25 | 25 | for w, g in [(want, got), (want2, got2)]) |
|
26 | 26 | |
|
27 | 27 | # TODO: migrate doctests to py3 and enable them on both versions |
|
28 |
def testmod(name, optionflags=0, testtarget=None, py2=True, py3= |
|
|
28 | def testmod(name, optionflags=0, testtarget=None, py2=True, py3=True): | |
|
29 | 29 | if not (not ispy3 and py2 or ispy3 and py3): |
|
30 | 30 | return |
|
31 | 31 | __import__(name) |
|
32 | 32 | mod = sys.modules[name] |
|
33 | 33 | if testtarget is not None: |
|
34 | 34 | mod = getattr(mod, testtarget) |
|
35 | 35 | |
|
36 | 36 | # minimal copy of doctest.testmod() |
|
37 | 37 | finder = doctest.DocTestFinder() |
|
38 | 38 | checker = None |
|
39 | 39 | if ispy3: |
|
40 | 40 | checker = py3docchecker() |
|
41 | 41 | runner = doctest.DocTestRunner(checker=checker, optionflags=optionflags) |
|
42 | 42 | for test in finder.find(mod, name): |
|
43 | 43 | runner.run(test) |
|
44 | 44 | runner.summarize() |
|
45 | 45 | |
|
46 | 46 | testmod('mercurial.changegroup') |
|
47 | 47 | testmod('mercurial.changelog') |
|
48 | 48 | testmod('mercurial.color') |
|
49 | 49 | testmod('mercurial.config') |
|
50 | 50 | testmod('mercurial.context') |
|
51 |
testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE |
|
|
51 | testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE, | |
|
52 | py3=False) # py3: use of str() | |
|
52 | 53 | testmod('mercurial.dispatch') |
|
53 | testmod('mercurial.encoding') | |
|
54 | testmod('mercurial.formatter') | |
|
54 | testmod('mercurial.encoding', py3=False) # py3: multiple encoding issues | |
|
55 | testmod('mercurial.formatter', py3=False) # py3: write bytes to stdout | |
|
55 | 56 | testmod('mercurial.hg') |
|
56 | testmod('mercurial.hgweb.hgwebdir_mod') | |
|
57 | testmod('mercurial.hgweb.hgwebdir_mod', py3=False) # py3: repr(bytes) ? | |
|
57 | 58 | testmod('mercurial.match') |
|
58 | 59 | testmod('mercurial.mdiff') |
|
59 | 60 | testmod('mercurial.minirst') |
|
60 | testmod('mercurial.patch') | |
|
61 | testmod('mercurial.pathutil') | |
|
61 | testmod('mercurial.patch', py3=False) # py3: bytes[n], etc. ? | |
|
62 | testmod('mercurial.pathutil', py3=False) # py3: os.sep | |
|
62 | 63 | testmod('mercurial.parser') |
|
63 |
testmod('mercurial.pycompat' |
|
|
64 | testmod('mercurial.pycompat') | |
|
64 | 65 | testmod('mercurial.revsetlang') |
|
65 | 66 | testmod('mercurial.smartset') |
|
66 | testmod('mercurial.store') | |
|
67 | testmod('mercurial.store', py3=False) # py3: bytes[n] | |
|
67 | 68 | testmod('mercurial.subrepo') |
|
68 | 69 | testmod('mercurial.templatefilters') |
|
69 | 70 | testmod('mercurial.templater') |
|
70 | testmod('mercurial.ui') | |
|
71 | testmod('mercurial.ui', py3=False) # py3: __name__ | |
|
71 | 72 | testmod('mercurial.url') |
|
72 | testmod('mercurial.util') | |
|
73 | testmod('mercurial.util', py3=False) # py3: multiple bytes/unicode issues | |
|
73 | 74 | testmod('mercurial.util', testtarget='platform') |
|
74 | testmod('hgext.convert.convcmd') | |
|
75 | testmod('hgext.convert.convcmd', py3=False) # py3: use of str() ? | |
|
75 | 76 | testmod('hgext.convert.cvsps') |
|
76 | 77 | testmod('hgext.convert.filemap') |
|
77 | 78 | testmod('hgext.convert.p4') |
|
78 | 79 | testmod('hgext.convert.subversion') |
|
79 | 80 | testmod('hgext.mq') |
General Comments 0
You need to be logged in to leave comments.
Login now