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