-
-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathtest_util.py
61 lines (50 loc) · 1.6 KB
/
test_util.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import subprocess
from textwrap import dedent
from unittesting import DeferrableTestCase
from SublimeLinter.tests.mockito import (
unstub,
verify,
when,
)
from SublimeLinter.lint import util
class TestCheckOutput(DeferrableTestCase):
def teardown(self):
unstub()
def test_emits_nicely_formatted_warning(self):
when(util.logger).warning(...)
cmd = ["python", "--foo"]
returncode = 2
output = bytes(dedent("""\
unknown option --foo
unknown option --foo
unknown option --foo
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
""".rstrip()), "utf8")
when(subprocess).check_output(...).thenRaise(
subprocess.CalledProcessError(returncode, cmd, output)
)
try:
util.check_output(cmd)
except Exception:
...
verify(util.logger).warning("""\
Executing `python --foo` failed
Command '['python', '--foo']' returned non-zero exit status 2.
...
unknown option --foo
unknown option --foo
unknown option --foo
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.""")
def test_accepts_any_exception(self):
when(util.logger).warning(...)
when(subprocess).check_output(...).thenRaise(Exception("some message"))
cmd = ["python", "--foo"]
try:
util.check_output(cmd)
except Exception:
...
verify(util.logger).warning("""\
Executing `python --foo` failed
some message""")