Show More
@@ -1,116 +1,115 | |||
|
1 | 1 | # Copyright 2012 Facebook |
|
2 | 2 | # |
|
3 | 3 | # This software may be used and distributed according to the terms of the |
|
4 | 4 | # GNU General Public License version 2 or any later version. |
|
5 | 5 | """Find tests that newly pass under Python 3. |
|
6 | 6 | |
|
7 | 7 | The approach is simple: we maintain a whitelist of Python 3 passing |
|
8 | 8 | tests in the repository, and periodically run all the /other/ tests |
|
9 | 9 | and look for new passes. Any newly passing tests get automatically |
|
10 | 10 | added to the whitelist. |
|
11 | 11 | |
|
12 | 12 | You probably want to run it like this: |
|
13 | 13 | |
|
14 | 14 | $ cd tests |
|
15 | 15 | $ python3 ../contrib/python3-ratchet.py \ |
|
16 | 16 | > --working-tests=../contrib/python3-whitelist |
|
17 | 17 | """ |
|
18 | 18 | from __future__ import print_function |
|
19 | 19 | from __future__ import absolute_import |
|
20 | 20 | |
|
21 | 21 | import argparse |
|
22 | 22 | import json |
|
23 | 23 | import os |
|
24 | 24 | import subprocess |
|
25 | 25 | import sys |
|
26 | 26 | |
|
27 | 27 | _hgenv = dict(os.environ) |
|
28 | 28 | _hgenv.update({ |
|
29 | 29 | 'HGPLAIN': '1', |
|
30 | 30 | }) |
|
31 | 31 | |
|
32 | 32 | _HG_FIRST_CHANGE = '9117c6561b0bd7792fa13b50d28239d51b78e51f' |
|
33 | 33 | |
|
34 | 34 | def _runhg(*args): |
|
35 | 35 | return subprocess.check_output(args, env=_hgenv) |
|
36 | 36 | |
|
37 | 37 | def _is_hg_repo(path): |
|
38 | 38 | return _runhg('hg', 'log', '-R', path, |
|
39 | 39 | '-r0', '--template={node}').strip() == _HG_FIRST_CHANGE |
|
40 | 40 | |
|
41 | 41 | def _py3default(): |
|
42 | 42 | if sys.version_info[0] >= 3: |
|
43 | 43 | return sys.executable |
|
44 | 44 | return 'python3' |
|
45 | 45 | |
|
46 | 46 | def main(argv=()): |
|
47 | 47 | p = argparse.ArgumentParser() |
|
48 | 48 | p.add_argument('--working-tests', |
|
49 | 49 | help='List of tests that already work in Python 3.') |
|
50 | 50 | p.add_argument('--commit-to-repo', |
|
51 | 51 | help='If set, commit newly fixed tests to the given repo') |
|
52 | 52 | p.add_argument('-j', default=os.sysconf(r'SC_NPROCESSORS_ONLN'), type=int, |
|
53 | 53 | help='Number of parallel tests to run.') |
|
54 | 54 | p.add_argument('--python3', default=_py3default(), |
|
55 | 55 | help='python3 interpreter to use for test run') |
|
56 | 56 | p.add_argument('--commit-user', |
|
57 | 57 | default='python3-ratchet@mercurial-scm.org', |
|
58 | 58 | help='Username to specify when committing to a repo.') |
|
59 | 59 | opts = p.parse_args(argv) |
|
60 | 60 | if opts.commit_to_repo: |
|
61 | 61 | if not _is_hg_repo(opts.commit_to_repo): |
|
62 | 62 | print('abort: specified repository is not the hg repository') |
|
63 | 63 | sys.exit(1) |
|
64 | 64 | if not opts.working_tests or not os.path.isfile(opts.working_tests): |
|
65 | 65 | print('abort: --working-tests must exist and be a file (got %r)' % |
|
66 | 66 | opts.working_tests) |
|
67 | 67 | sys.exit(1) |
|
68 | 68 | elif opts.commit_to_repo: |
|
69 | 69 | root = _runhg('hg', 'root').strip() |
|
70 | 70 | if not opts.working_tests.startswith(root): |
|
71 | 71 | print('abort: if --commit-to-repo is given, ' |
|
72 | 72 | '--working-tests must be from that repo') |
|
73 | 73 | sys.exit(1) |
|
74 | 74 | try: |
|
75 | 75 | subprocess.check_call([opts.python3, '-c', |
|
76 | 76 | 'import sys ; ' |
|
77 | 77 | 'assert ((3, 5) <= sys.version_info < (3, 6) ' |
|
78 | 78 | 'or sys.version_info >= (3, 6, 2))']) |
|
79 | 79 | except subprocess.CalledProcessError: |
|
80 | 80 | print('warning: Python 3.6.0 and 3.6.1 have ' |
|
81 | 81 | 'a bug which breaks Mercurial') |
|
82 | 82 | print('(see https://bugs.python.org/issue29714 for details)') |
|
83 | # TODO(augie): uncomment exit when Python 3.6.2 is available | |
|
84 | # sys.exit(1) | |
|
83 | sys.exit(1) | |
|
85 | 84 | |
|
86 | 85 | rt = subprocess.Popen([opts.python3, 'run-tests.py', '-j', str(opts.j), |
|
87 | 86 | '--blacklist', opts.working_tests, '--json']) |
|
88 | 87 | rt.wait() |
|
89 | 88 | with open('report.json') as f: |
|
90 | 89 | data = f.read() |
|
91 | 90 | report = json.loads(data.split('=', 1)[1]) |
|
92 | 91 | newpass = set() |
|
93 | 92 | for test, result in report.items(): |
|
94 | 93 | if result['result'] != 'success': |
|
95 | 94 | continue |
|
96 | 95 | # A new passing test! Huzzah! |
|
97 | 96 | newpass.add(test) |
|
98 | 97 | if newpass: |
|
99 | 98 | # We already validated the repo, so we can just dive right in |
|
100 | 99 | # and commit. |
|
101 | 100 | if opts.commit_to_repo: |
|
102 | 101 | print(len(newpass), 'new passing tests on Python 3!') |
|
103 | 102 | with open(opts.working_tests) as f: |
|
104 | 103 | oldpass = {l for l in f.read().splitlines() if l} |
|
105 | 104 | with open(opts.working_tests, 'w') as f: |
|
106 | 105 | for p in sorted(oldpass | newpass): |
|
107 | 106 | f.write('%s\n' % p) |
|
108 | 107 | _runhg('hg', 'commit', '-R', opts.commit_to_repo, |
|
109 | 108 | '--user', opts.commit_user, |
|
110 | 109 | '--message', 'python3: expand list of passing tests') |
|
111 | 110 | else: |
|
112 | 111 | print('Newly passing tests:', '\n'.join(sorted(newpass))) |
|
113 | 112 | sys.exit(2) |
|
114 | 113 | |
|
115 | 114 | if __name__ == '__main__': |
|
116 | 115 | main(sys.argv[1:]) |
General Comments 0
You need to be logged in to leave comments.
Login now