Show More
@@ -1,94 +1,166 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 | from __future__ import print_function | |||
4 |
|
5 | |||
5 | import doctest |
|
6 | import doctest | |
6 | import os |
|
7 | import os | |
7 | import re |
|
8 | import re | |
|
9 | import subprocess | |||
8 | import sys |
|
10 | import sys | |
9 |
|
11 | |||
10 | ispy3 = sys.version_info[0] >= 3 |
|
12 | ispy3 = sys.version_info[0] >= 3 | |
11 |
|
13 | |||
12 | if 'TERM' in os.environ: |
|
14 | if 'TERM' in os.environ: | |
13 | del os.environ['TERM'] |
|
15 | del os.environ['TERM'] | |
14 |
|
16 | |||
15 |
|
17 | |||
16 | class py3docchecker(doctest.OutputChecker): |
|
18 | class py3docchecker(doctest.OutputChecker): | |
17 | def check_output(self, want, got, optionflags): |
|
19 | def check_output(self, want, got, optionflags): | |
18 | want2 = re.sub(r'''\bu(['"])(.*?)\1''', r'\1\2\1', want) # py2: u'' |
|
20 | want2 = re.sub(r'''\bu(['"])(.*?)\1''', r'\1\2\1', want) # py2: u'' | |
19 | got2 = re.sub(r'''\bb(['"])(.*?)\1''', r'\1\2\1', got) # py3: b'' |
|
21 | got2 = re.sub(r'''\bb(['"])(.*?)\1''', r'\1\2\1', got) # py3: b'' | |
20 | # py3: <exc.name>: b'<msg>' -> <name>: <msg> |
|
22 | # py3: <exc.name>: b'<msg>' -> <name>: <msg> | |
21 | # <exc.name>: <others> -> <name>: <others> |
|
23 | # <exc.name>: <others> -> <name>: <others> | |
22 | got2 = re.sub( |
|
24 | got2 = re.sub( | |
23 | r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''', |
|
25 | r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''', | |
24 | r'\1: \3', |
|
26 | r'\1: \3', | |
25 | got2, |
|
27 | got2, | |
26 | re.MULTILINE, |
|
28 | re.MULTILINE, | |
27 | ) |
|
29 | ) | |
28 | got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE) |
|
30 | got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE) | |
29 | return any( |
|
31 | return any( | |
30 | doctest.OutputChecker.check_output(self, w, g, optionflags) |
|
32 | doctest.OutputChecker.check_output(self, w, g, optionflags) | |
31 | for w, g in [(want, got), (want2, got2)] |
|
33 | for w, g in [(want, got), (want2, got2)] | |
32 | ) |
|
34 | ) | |
33 |
|
35 | |||
34 |
|
36 | |||
35 | def testmod(name, optionflags=0, testtarget=None): |
|
37 | def testmod(name, optionflags=0, testtarget=None): | |
36 | __import__(name) |
|
38 | __import__(name) | |
37 | mod = sys.modules[name] |
|
39 | mod = sys.modules[name] | |
38 | if testtarget is not None: |
|
40 | if testtarget is not None: | |
39 | mod = getattr(mod, testtarget) |
|
41 | mod = getattr(mod, testtarget) | |
40 |
|
42 | |||
41 | # minimal copy of doctest.testmod() |
|
43 | # minimal copy of doctest.testmod() | |
42 | finder = doctest.DocTestFinder() |
|
44 | finder = doctest.DocTestFinder() | |
43 | checker = None |
|
45 | checker = None | |
44 | if ispy3: |
|
46 | if ispy3: | |
45 | checker = py3docchecker() |
|
47 | checker = py3docchecker() | |
46 | runner = doctest.DocTestRunner(checker=checker, optionflags=optionflags) |
|
48 | runner = doctest.DocTestRunner(checker=checker, optionflags=optionflags) | |
47 | for test in finder.find(mod, name): |
|
49 | for test in finder.find(mod, name): | |
48 | runner.run(test) |
|
50 | runner.run(test) | |
49 | runner.summarize() |
|
51 | runner.summarize() | |
50 |
|
52 | |||
51 |
|
53 | |||
52 | testmod('mercurial.changelog') |
|
54 | DONT_RUN = [] | |
53 | testmod('mercurial.cmdutil') |
|
55 | ||
54 | testmod('mercurial.color') |
|
56 | # Exceptions to the defaults for a given detected module. The value for each | |
55 | testmod('mercurial.config') |
|
57 | # module name is a list of dicts that specify the kwargs to pass to testmod. | |
56 | testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE) |
|
58 | # testmod is called once per item in the list, so an empty list will cause the | |
57 | testmod('mercurial.encoding') |
|
59 | # module to not be tested. | |
58 | testmod('mercurial.fancyopts') |
|
60 | testmod_arg_overrides = { | |
59 | testmod('mercurial.formatter') |
|
61 | 'i18n.check-translation': DONT_RUN, # may require extra installation | |
60 | testmod('mercurial.hg') |
|
62 | 'mercurial.dagparser': [{'optionflags': doctest.NORMALIZE_WHITESPACE}], | |
61 | testmod('mercurial.hgweb.hgwebdir_mod') |
|
63 | 'mercurial.keepalive': DONT_RUN, # >>> is an example, not a doctest | |
62 | testmod('mercurial.match') |
|
64 | 'mercurial.posix': DONT_RUN, # run by mercurial.platform | |
63 | testmod('mercurial.mdiff') |
|
65 | 'mercurial.statprof': DONT_RUN, # >>> is an example, not a doctest | |
64 | testmod('mercurial.minirst') |
|
66 | 'mercurial.util': [{}, {'testtarget': 'platform'}], # run twice! | |
65 | testmod('mercurial.parser') |
|
67 | 'mercurial.windows': DONT_RUN, # run by mercurial.platform | |
66 | testmod('mercurial.patch') |
|
68 | 'tests.test-url': [{'optionflags': doctest.NORMALIZE_WHITESPACE}], | |
67 | testmod('mercurial.pathutil') |
|
69 | } | |
68 | testmod('mercurial.pycompat') |
|
70 | ||
69 | testmod('mercurial.revlogutils.deltas') |
|
71 | doctest_indicator = '\n\\s*>>> ' | |
70 | testmod('mercurial.revset') |
|
72 | fileset = 'set:(**.py and grep("%s"))' % doctest_indicator | |
71 | testmod('mercurial.revsetlang') |
|
73 | ||
72 | testmod('mercurial.simplemerge') |
|
74 | files = subprocess.check_output( | |
73 | testmod('mercurial.smartset') |
|
75 | "hg files --print0 '%s'" % fileset, | |
74 | testmod('mercurial.store') |
|
76 | shell=True, | |
75 | testmod('mercurial.subrepo') |
|
77 | cwd=os.path.dirname(os.environ['TESTDIR']), | |
76 | testmod('mercurial.templater') |
|
78 | ).split(b'\0') | |
77 | testmod('mercurial.ui') |
|
79 | ||
78 | testmod('mercurial.util') |
|
80 | mods_tested = set() | |
79 | testmod('mercurial.util', testtarget='platform') # windows.py or posix.py |
|
81 | for f in files: | |
80 | testmod('mercurial.utils.dateutil') |
|
82 | if not f: | |
81 | testmod('mercurial.utils.stringutil') |
|
83 | continue | |
82 | testmod('hgext.convert.convcmd') |
|
84 | ||
83 | testmod('hgext.convert.cvsps') |
|
85 | if ispy3: | |
84 | testmod('hgext.convert.filemap') |
|
86 | f = f.decode() | |
85 | testmod('hgext.convert.p4') |
|
87 | ||
86 | testmod('hgext.convert.subversion') |
|
88 | modname = f.replace('.py', '').replace('\\', '.').replace('/', '.') | |
87 | testmod('hgext.fix') |
|
89 | ||
88 | testmod('hgext.mq') |
|
90 | # Third-party modules aren't our responsibility to test, and the modules in | |
89 | # Helper scripts in tests/ that have doctests: |
|
91 | # contrib generally do not have doctests in a good state, plus they're hard | |
90 | testmod('drawdag') |
|
92 | # to import if this test is running with py2, so we just skip both for now. | |
91 | testmod('test-run-tests') |
|
93 | if modname.startswith('mercurial.thirdparty.') or modname.startswith( | |
|
94 | 'contrib.' | |||
|
95 | ): | |||
|
96 | continue | |||
|
97 | ||||
|
98 | for kwargs in testmod_arg_overrides.get(modname, [{}]): | |||
|
99 | mods_tested.add((modname, '%r' % (kwargs,))) | |||
|
100 | if modname.startswith('tests.'): | |||
|
101 | # On py2, we can't import from tests.foo, but it works on both py2 | |||
|
102 | # and py3 with the way that PYTHONPATH is setup to import without | |||
|
103 | # the 'tests.' prefix, so we do that. | |||
|
104 | modname = modname[len('tests.') :] | |||
|
105 | ||||
|
106 | testmod(modname, **kwargs) | |||
92 |
|
107 | |||
93 | # Disabled since it requires extra modules that might not be installed. |
|
108 | # Meta-test: let's make sure that we actually ran what we expected to, above. | |
94 | # testmod('i18n.check-translation') |
|
109 | # Each item in the set is a 2-tuple of module name and stringified kwargs passed | |
|
110 | # to testmod. | |||
|
111 | expected_mods_tested = set( | |||
|
112 | [ | |||
|
113 | ('hgext.convert.convcmd', '{}'), | |||
|
114 | ('hgext.convert.cvsps', '{}'), | |||
|
115 | ('hgext.convert.filemap', '{}'), | |||
|
116 | ('hgext.convert.p4', '{}'), | |||
|
117 | ('hgext.convert.subversion', '{}'), | |||
|
118 | ('hgext.fix', '{}'), | |||
|
119 | ('hgext.mq', '{}'), | |||
|
120 | ('mercurial.changelog', '{}'), | |||
|
121 | ('mercurial.cmdutil', '{}'), | |||
|
122 | ('mercurial.color', '{}'), | |||
|
123 | ('mercurial.config', '{}'), | |||
|
124 | ('mercurial.dagparser', "{'optionflags': 4}"), | |||
|
125 | ('mercurial.encoding', '{}'), | |||
|
126 | ('mercurial.fancyopts', '{}'), | |||
|
127 | ('mercurial.formatter', '{}'), | |||
|
128 | ('mercurial.hg', '{}'), | |||
|
129 | ('mercurial.hgweb.hgwebdir_mod', '{}'), | |||
|
130 | ('mercurial.match', '{}'), | |||
|
131 | ('mercurial.mdiff', '{}'), | |||
|
132 | ('mercurial.minirst', '{}'), | |||
|
133 | ('mercurial.parser', '{}'), | |||
|
134 | ('mercurial.patch', '{}'), | |||
|
135 | ('mercurial.pathutil', '{}'), | |||
|
136 | ('mercurial.pycompat', '{}'), | |||
|
137 | ('mercurial.revlogutils.deltas', '{}'), | |||
|
138 | ('mercurial.revset', '{}'), | |||
|
139 | ('mercurial.revsetlang', '{}'), | |||
|
140 | ('mercurial.simplemerge', '{}'), | |||
|
141 | ('mercurial.smartset', '{}'), | |||
|
142 | ('mercurial.store', '{}'), | |||
|
143 | ('mercurial.subrepo', '{}'), | |||
|
144 | ('mercurial.templater', '{}'), | |||
|
145 | ('mercurial.ui', '{}'), | |||
|
146 | ('mercurial.util', "{'testtarget': 'platform'}"), | |||
|
147 | ('mercurial.util', '{}'), | |||
|
148 | ('mercurial.utils.dateutil', '{}'), | |||
|
149 | ('mercurial.utils.stringutil', '{}'), | |||
|
150 | ('tests.drawdag', '{}'), | |||
|
151 | ('tests.test-run-tests', '{}'), | |||
|
152 | ('tests.test-url', "{'optionflags': 4}"), | |||
|
153 | ] | |||
|
154 | ) | |||
|
155 | ||||
|
156 | unexpectedly_run = mods_tested.difference(expected_mods_tested) | |||
|
157 | not_run = expected_mods_tested.difference(mods_tested) | |||
|
158 | ||||
|
159 | if unexpectedly_run: | |||
|
160 | print('Unexpectedly ran (probably need to add to list):') | |||
|
161 | for r in sorted(unexpectedly_run): | |||
|
162 | print(' %r' % (r,)) | |||
|
163 | if not_run: | |||
|
164 | print('Expected to run, but was not run (doctest removed?):') | |||
|
165 | for r in sorted(not_run): | |||
|
166 | print(' %r' % (r,)) |
General Comments 0
You need to be logged in to leave comments.
Login now