##// END OF EJS Templates
test-doctest: include dateutil...
Jun Wu -
r44169:92518ca6 default draft
parent child Browse files
Show More
@@ -1,94 +1,95 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 re
8 import sys
8 import sys
9
9
10 ispy3 = sys.version_info[0] >= 3
10 ispy3 = sys.version_info[0] >= 3
11
11
12 if 'TERM' in os.environ:
12 if 'TERM' in os.environ:
13 del os.environ['TERM']
13 del os.environ['TERM']
14
14
15
15
16 class py3docchecker(doctest.OutputChecker):
16 class py3docchecker(doctest.OutputChecker):
17 def check_output(self, want, got, optionflags):
17 def check_output(self, want, got, optionflags):
18 want2 = re.sub(r'''\bu(['"])(.*?)\1''', r'\1\2\1', want) # py2: u''
18 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''
19 got2 = re.sub(r'''\bb(['"])(.*?)\1''', r'\1\2\1', got) # py3: b''
20 # py3: <exc.name>: b'<msg>' -> <name>: <msg>
20 # py3: <exc.name>: b'<msg>' -> <name>: <msg>
21 # <exc.name>: <others> -> <name>: <others>
21 # <exc.name>: <others> -> <name>: <others>
22 got2 = re.sub(
22 got2 = re.sub(
23 r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''',
23 r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''',
24 r'\1: \3',
24 r'\1: \3',
25 got2,
25 got2,
26 re.MULTILINE,
26 re.MULTILINE,
27 )
27 )
28 got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE)
28 got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE)
29 return any(
29 return any(
30 doctest.OutputChecker.check_output(self, w, g, optionflags)
30 doctest.OutputChecker.check_output(self, w, g, optionflags)
31 for w, g in [(want, got), (want2, got2)]
31 for w, g in [(want, got), (want2, got2)]
32 )
32 )
33
33
34
34
35 def testmod(name, optionflags=0, testtarget=None):
35 def testmod(name, optionflags=0, testtarget=None):
36 __import__(name)
36 __import__(name)
37 mod = sys.modules[name]
37 mod = sys.modules[name]
38 if testtarget is not None:
38 if testtarget is not None:
39 mod = getattr(mod, testtarget)
39 mod = getattr(mod, testtarget)
40
40
41 # minimal copy of doctest.testmod()
41 # minimal copy of doctest.testmod()
42 finder = doctest.DocTestFinder()
42 finder = doctest.DocTestFinder()
43 checker = None
43 checker = None
44 if ispy3:
44 if ispy3:
45 checker = py3docchecker()
45 checker = py3docchecker()
46 runner = doctest.DocTestRunner(checker=checker, optionflags=optionflags)
46 runner = doctest.DocTestRunner(checker=checker, optionflags=optionflags)
47 for test in finder.find(mod, name):
47 for test in finder.find(mod, name):
48 runner.run(test)
48 runner.run(test)
49 runner.summarize()
49 runner.summarize()
50
50
51
51
52 testmod('mercurial.changegroup')
52 testmod('mercurial.changegroup')
53 testmod('mercurial.changelog')
53 testmod('mercurial.changelog')
54 testmod('mercurial.cmdutil')
54 testmod('mercurial.cmdutil')
55 testmod('mercurial.color')
55 testmod('mercurial.color')
56 testmod('mercurial.config')
56 testmod('mercurial.config')
57 testmod('mercurial.context')
57 testmod('mercurial.context')
58 testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE)
58 testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE)
59 testmod('mercurial.dispatch')
59 testmod('mercurial.dispatch')
60 testmod('mercurial.encoding')
60 testmod('mercurial.encoding')
61 testmod('mercurial.fancyopts')
61 testmod('mercurial.fancyopts')
62 testmod('mercurial.formatter')
62 testmod('mercurial.formatter')
63 testmod('mercurial.hg')
63 testmod('mercurial.hg')
64 testmod('mercurial.hgweb.hgwebdir_mod')
64 testmod('mercurial.hgweb.hgwebdir_mod')
65 testmod('mercurial.match')
65 testmod('mercurial.match')
66 testmod('mercurial.mdiff')
66 testmod('mercurial.mdiff')
67 testmod('mercurial.minirst')
67 testmod('mercurial.minirst')
68 testmod('mercurial.patch')
68 testmod('mercurial.patch')
69 testmod('mercurial.pathutil')
69 testmod('mercurial.pathutil')
70 testmod('mercurial.parser')
70 testmod('mercurial.parser')
71 testmod('mercurial.pycompat')
71 testmod('mercurial.pycompat')
72 testmod('mercurial.revlog')
72 testmod('mercurial.revlog')
73 testmod('mercurial.revlogutils.deltas')
73 testmod('mercurial.revlogutils.deltas')
74 testmod('mercurial.revset')
74 testmod('mercurial.revset')
75 testmod('mercurial.revsetlang')
75 testmod('mercurial.revsetlang')
76 testmod('mercurial.smartset')
76 testmod('mercurial.smartset')
77 testmod('mercurial.store')
77 testmod('mercurial.store')
78 testmod('mercurial.subrepo')
78 testmod('mercurial.subrepo')
79 testmod('mercurial.templatefilters')
79 testmod('mercurial.templatefilters')
80 testmod('mercurial.templater')
80 testmod('mercurial.templater')
81 testmod('mercurial.ui')
81 testmod('mercurial.ui')
82 testmod('mercurial.url')
82 testmod('mercurial.url')
83 testmod('mercurial.util')
83 testmod('mercurial.util')
84 testmod('mercurial.util', testtarget='platform')
84 testmod('mercurial.util', testtarget='platform')
85 testmod('mercurial.utils.dateutil')
85 testmod('mercurial.utils.stringutil')
86 testmod('mercurial.utils.stringutil')
86 testmod('hgext.convert.convcmd')
87 testmod('hgext.convert.convcmd')
87 testmod('hgext.convert.cvsps')
88 testmod('hgext.convert.cvsps')
88 testmod('hgext.convert.filemap')
89 testmod('hgext.convert.filemap')
89 testmod('hgext.convert.p4')
90 testmod('hgext.convert.p4')
90 testmod('hgext.convert.subversion')
91 testmod('hgext.convert.subversion')
91 testmod('hgext.fix')
92 testmod('hgext.fix')
92 testmod('hgext.mq')
93 testmod('hgext.mq')
93 # Helper scripts in tests/ that have doctests:
94 # Helper scripts in tests/ that have doctests:
94 testmod('drawdag')
95 testmod('drawdag')
General Comments 0
You need to be logged in to leave comments. Login now