##// END OF EJS Templates
tests: make test-doctest.t automatically find files to run tests on...
Kyle Lippincott -
r45055:0af56d3e default
parent child Browse files
Show More
@@ -1,10 +1,12 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
@@ -49,46 +51,116 b' def testmod(name, optionflags=0, testtar'
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