Skip to content

Commit af6b456

Browse files
authored
Merge pull request #2 from python/master
Sync Fork from Upstream Repo
2 parents ec4dbc1 + 5336f27 commit af6b456

File tree

4 files changed

+316
-439
lines changed

4 files changed

+316
-439
lines changed

.travis.yml

+14-12
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,28 @@ dist: xenial
1717

1818
env:
1919
TOXENV=py
20-
EXTRA_ARGS="-n 12"
20+
EXTRA_ARGS="-n 2"
2121
TEST_MYPYC=0
2222
PYTHON_DEBUG_BUILD=0
2323

2424
jobs:
2525
include:
2626
# Specifically request 3.5.1 because we need to be compatible with that.
27-
- name: "run test suite with python 3.5.1"
27+
- name: "run test suite with python 3.5.1 (compiled with mypyc)"
2828
python: 3.5.1
2929
dist: trusty
30+
env:
31+
- TOXENV=py
32+
- EXTRA_ARGS="-n 2"
33+
- TEST_MYPYC=1
3034
- name: "run test suite with python 3.6"
3135
python: 3.6 # 3.6.3 pip 9.0.1
32-
- name: "run test suite with python 3.7"
33-
python: 3.7 # 3.7.0 pip 10.0.1
36+
- name: "run test suite with python 3.7 (compiled with mypyc)"
37+
python: 3.7
38+
env:
39+
- TOXENV=py
40+
- EXTRA_ARGS="-n 2"
41+
- TEST_MYPYC=1
3442
- name: "run test suite with python 3.8"
3543
python: 3.8
3644
- name: "run mypyc runtime tests with python 3.6 debug build"
@@ -39,20 +47,14 @@ jobs:
3947
- TOXENV=py36
4048
- PYTHONVERSION=3.6.8
4149
- PYTHON_DEBUG_BUILD=1
42-
- EXTRA_ARGS="-n 12 mypyc/test/test_run.py mypyc/test/test_external.py"
50+
- EXTRA_ARGS="-n 2 mypyc/test/test_run.py mypyc/test/test_external.py"
4351
- name: "run mypyc runtime tests with python 3.6 on OS X"
4452
os: osx
4553
osx_image: xcode8.3
4654
language: generic
4755
env:
4856
- PYTHONVERSION=3.6.3
49-
- EXTRA_ARGS="-n 12 mypyc/test/test_run.py mypyc/test/test_external.py"
50-
- name: "run test suite with python 3.7 (compiled with mypyc)"
51-
python: 3.7
52-
env:
53-
- TOXENV=py
54-
- EXTRA_ARGS="-n 12"
55-
- TEST_MYPYC=1
57+
- EXTRA_ARGS="-n 2 mypyc/test/test_run.py mypyc/test/test_external.py"
5658
- name: "type check our own code"
5759
python: 3.7
5860
env:

runtests.py

+80-18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
2+
import subprocess
3+
from subprocess import Popen
24
from os import system
35
from sys import argv, exit, platform, executable, version_info
46

5-
prog, *args = argv
6-
77

88
# Use the Python provided to execute the script, or fall back to a sane default
99
if version_info >= (3, 5, 0):
@@ -25,6 +25,9 @@
2525
STUBGEN_PY = 'StubgenPythonSuite'
2626
MYPYC_RUN = 'TestRun'
2727
MYPYC_RUN_MULTI = 'TestRunMultiFile'
28+
MYPYC_EXTERNAL = 'TestExternal'
29+
MYPYC_COMMAND_LINE = 'TestCommandLine'
30+
ERROR_STREAM = 'ErrorStreamSuite'
2831

2932

3033
ALL_NON_FAST = [CMDLINE,
@@ -36,7 +39,10 @@
3639
STUBGEN_CMD,
3740
STUBGEN_PY,
3841
MYPYC_RUN,
39-
MYPYC_RUN_MULTI]
42+
MYPYC_RUN_MULTI,
43+
MYPYC_EXTERNAL,
44+
MYPYC_COMMAND_LINE,
45+
ERROR_STREAM]
4046

4147
# We split the pytest run into three parts to improve test
4248
# parallelization. Each run should have tests that each take a roughly similar
@@ -55,31 +61,87 @@
5561
STUBGEN_PY]),
5662
# Test cases that may take seconds to run each
5763
'pytest-slow': 'pytest -k "%s"' % ' or '.join(
58-
[SAMPLES, TYPESHED, PEP561, DAEMON, MYPYC_RUN, MYPYC_RUN_MULTI]),
64+
[SAMPLES,
65+
TYPESHED,
66+
PEP561,
67+
DAEMON,
68+
MYPYC_RUN,
69+
MYPYC_RUN_MULTI,
70+
MYPYC_EXTERNAL,
71+
MYPYC_COMMAND_LINE,
72+
ERROR_STREAM]),
5973
}
6074

6175
# Stop run immediately if these commands fail
6276
FAST_FAIL = ['self', 'lint']
6377

6478
assert all(cmd in cmds for cmd in FAST_FAIL)
6579

66-
if not set(args).issubset(cmds):
67-
print("usage:", prog, " ".join('[%s]' % k for k in cmds))
68-
exit(1)
69-
70-
if not args:
71-
args = list(cmds)
72-
73-
status = 0
7480

75-
for arg in args:
76-
cmd = cmds[arg]
77-
print('run %s: %s' % (arg, cmd))
81+
def run_cmd(name: str) -> int:
82+
status = 0
83+
cmd = cmds[name]
84+
print('run %s: %s' % (name, cmd))
7885
res = (system(cmd) & 0x7F00) >> 8
7986
if res:
80-
print('\nFAILED: %s' % arg)
87+
print('\nFAILED: %s' % name)
8188
status = res
82-
if arg in FAST_FAIL:
89+
if name in FAST_FAIL:
8390
exit(status)
91+
return status
92+
93+
94+
def start_background_cmd(name: str) -> Popen:
95+
cmd = cmds[name]
96+
proc = subprocess.Popen(cmd,
97+
shell=True,
98+
stderr=subprocess.STDOUT,
99+
stdout=subprocess.PIPE)
100+
return proc
101+
102+
103+
def wait_background_cmd(name: str, proc: Popen) -> int:
104+
output = proc.communicate()[0]
105+
status = proc.returncode
106+
print('run %s: %s' % (name, cmds[name]))
107+
if status:
108+
print(output.decode().rstrip())
109+
print('\nFAILED: %s' % name)
110+
if name in FAST_FAIL:
111+
exit(status)
112+
return status
113+
114+
115+
def main() -> None:
116+
prog, *args = argv
117+
118+
if not set(args).issubset(cmds):
119+
print("usage:", prog, " ".join('[%s]' % k for k in cmds))
120+
exit(1)
121+
122+
if not args:
123+
args = list(cmds)
124+
125+
status = 0
126+
127+
if 'self' in args and 'lint' in args:
128+
# Perform lint and self check in parallel as it's faster.
129+
proc = start_background_cmd('lint')
130+
cmd_status = run_cmd('self')
131+
if cmd_status:
132+
status = cmd_status
133+
cmd_status = wait_background_cmd('lint', proc)
134+
if cmd_status:
135+
status = cmd_status
136+
args = [arg for arg in args if arg not in ('self', 'lint')]
137+
138+
for arg in args:
139+
cmd_status = run_cmd(arg)
140+
if cmd_status:
141+
status = cmd_status
142+
143+
exit(status)
144+
84145

85-
exit(status)
146+
if __name__ == '__main__':
147+
main()

0 commit comments

Comments
 (0)