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