Mercurial > hg
comparison tests/check-perf-code.py @ 29571:d1a7d9c279bb
tests: check importing modules in perf.py for historical portability
To check importing modules in perf.py for historical portability, this
patch lists up files by "hg files" both for "1.2" and tip, and builds
up "module whitelist" check from those files.
This patch uses "1.2" as earlier side version of "module whitelist",
because "mercurial.error" module is a blocker for loading perf.py with
Mercurial earlier than 1.2, and just importing "mercurial.error"
separately isn't enough.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 20 May 2016 09:47:35 +0900 |
parents | cbd240188e4e |
children | 14031d183048 |
comparison
equal
deleted
inserted
replaced
29570:cbd240188e4e | 29571:d1a7d9c279bb |
---|---|
14 # warnings | 14 # warnings |
15 [ | 15 [ |
16 ] | 16 ] |
17 ] | 17 ] |
18 | 18 |
19 def modulewhitelist(names): | |
20 replacement = [('.py', ''), ('.c', ''), # trim suffix | |
21 ('mercurial%s' % (os.sep), ''), # trim "mercurial/" path | |
22 ] | |
23 ignored = set(['__init__']) | |
24 modules = {} | |
25 | |
26 # convert from file name to module name, and count # of appearances | |
27 for name in names: | |
28 name = name.strip() | |
29 for old, new in replacement: | |
30 name = name.replace(old, new) | |
31 if name not in ignored: | |
32 modules[name] = modules.get(name, 0) + 1 | |
33 | |
34 # list up module names, which appear multiple times | |
35 whitelist = [] | |
36 for name, count in modules.items(): | |
37 if count > 1: | |
38 whitelist.append(name) | |
39 | |
40 return whitelist | |
41 | |
19 if __name__ == "__main__": | 42 if __name__ == "__main__": |
43 # in this case, it is assumed that result of "hg files" at | |
44 # multiple revisions is given via stdin | |
45 whitelist = modulewhitelist(sys.stdin) | |
46 assert whitelist, "module whitelist is empty" | |
47 | |
48 # build up module whitelist check from file names given at runtime | |
49 perfpypats[0].append( | |
50 # this matching pattern assumes importing modules from | |
51 # "mercurial" package in the current style below, for simplicity | |
52 # | |
53 # from mercurial import ( | |
54 # foo, | |
55 # bar, | |
56 # baz | |
57 # ) | |
58 ((r'from mercurial import [(][a-z0-9, \n#]*\n(?! *%s,|^[ #]*\n|[)])' | |
59 % ',| *'.join(whitelist)), | |
60 "import newer module separately in try clause for early Mercurial" | |
61 )) | |
62 | |
20 # import contrib/check-code.py as checkcode | 63 # import contrib/check-code.py as checkcode |
21 assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script" | 64 assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script" |
22 contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib') | 65 contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib') |
23 sys.path.insert(0, contribpath) | 66 sys.path.insert(0, contribpath) |
24 checkcode = __import__('check-code') | 67 checkcode = __import__('check-code') |