forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestapi.py
More file actions
45 lines (35 loc) · 1.38 KB
/
testapi.py
File metadata and controls
45 lines (35 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from io import StringIO
import sys
import mypy.api
from mypy.test.helpers import Suite
class APISuite(Suite):
def setUp(self) -> None:
self.sys_stdout = sys.stdout
self.sys_stderr = sys.stderr
sys.stdout = self.stdout = StringIO()
sys.stderr = self.stderr = StringIO()
def tearDown(self) -> None:
sys.stdout = self.sys_stdout
sys.stderr = self.sys_stderr
assert self.stdout.getvalue() == ''
assert self.stderr.getvalue() == ''
def test_capture_bad_opt(self) -> None:
"""stderr should be captured when a bad option is passed."""
_, stderr, _ = mypy.api.run(['--some-bad-option'])
assert isinstance(stderr, str)
assert stderr != ''
def test_capture_empty(self) -> None:
"""stderr should be captured when a bad option is passed."""
_, stderr, _ = mypy.api.run([])
assert isinstance(stderr, str)
assert stderr != ''
def test_capture_help(self) -> None:
"""stdout should be captured when --help is passed."""
stdout, _, _ = mypy.api.run(['--help'])
assert isinstance(stdout, str)
assert stdout != ''
def test_capture_version(self) -> None:
"""stdout should be captured when --version is passed."""
stdout, _, _ = mypy.api.run(['--version'])
assert isinstance(stdout, str)
assert stdout != ''