Skip to content

Commit 823245e

Browse files
tonyjoseph-flinn
authored andcommitted
Plugin tests: Use pytest.raises and assert message contents
See also: https://docs.pytest.org/en/6.1.2/reference.html#pytest-raises
1 parent f779439 commit 823245e

File tree

1 file changed

+30
-50
lines changed

1 file changed

+30
-50
lines changed

tests/test_plugin.py

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,101 +2,81 @@
22
"""Test for tmuxp plugin api."""
33
from __future__ import absolute_import
44

5+
import pytest
6+
57
from tmuxp.exc import TmuxpPluginException
68

79
from .fixtures.pluginsystem.partials.all_pass import AllVersionPassPlugin
8-
from .fixtures.pluginsystem.partials.tmux_version_fail import (
9-
TmuxVersionFailMinPlugin,
10-
TmuxVersionFailMaxPlugin,
11-
TmuxVersionFailIncompatiblePlugin,
12-
)
1310
from .fixtures.pluginsystem.partials.libtmux_version_fail import (
14-
LibtmuxVersionFailMinPlugin,
15-
LibtmuxVersionFailMaxPlugin,
1611
LibtmuxVersionFailIncompatiblePlugin,
12+
LibtmuxVersionFailMaxPlugin,
13+
LibtmuxVersionFailMinPlugin,
14+
)
15+
from .fixtures.pluginsystem.partials.tmux_version_fail import (
16+
TmuxVersionFailIncompatiblePlugin,
17+
TmuxVersionFailMaxPlugin,
18+
TmuxVersionFailMinPlugin,
1719
)
1820
from .fixtures.pluginsystem.partials.tmuxp_version_fail import (
19-
TmuxpVersionFailMinPlugin,
20-
TmuxpVersionFailMaxPlugin,
2121
TmuxpVersionFailIncompatiblePlugin,
22+
TmuxpVersionFailMaxPlugin,
23+
TmuxpVersionFailMinPlugin,
2224
)
2325

2426

2527
def test_all_pass():
26-
try:
27-
AllVersionPassPlugin()
28-
assert True
29-
except TmuxpPluginException:
30-
assert False
28+
AllVersionPassPlugin()
3129

3230

3331
def test_tmux_version_fail_min():
34-
try:
32+
with pytest.raises(TmuxpPluginException, match=r'Incompatible.*') as exc_info:
3533
TmuxVersionFailMinPlugin()
36-
assert False
37-
except TmuxpPluginException as error:
38-
assert 'Incompatible' in error.__str__()
34+
assert 'tmux-min-version-fail' in str(exc_info.value)
3935

4036

4137
def test_tmux_version_fail_max():
42-
try:
38+
with pytest.raises(TmuxpPluginException, match=r'Incompatible.*') as exc_info:
4339
TmuxVersionFailMaxPlugin()
44-
assert False
45-
except TmuxpPluginException as error:
46-
assert 'Incompatible' in error.__str__()
40+
assert 'tmux-max-version-fail' in str(exc_info.value)
4741

4842

4943
def test_tmux_version_fail_incompatible():
50-
try:
44+
with pytest.raises(TmuxpPluginException, match=r'Incompatible.*') as exc_info:
5145
TmuxVersionFailIncompatiblePlugin()
52-
assert False
53-
except TmuxpPluginException as error:
54-
assert 'Incompatible' in error.__str__()
46+
assert 'tmux-incompatible-version-fail' in str(exc_info.value)
5547

5648

5749
def test_tmuxp_version_fail_min():
58-
try:
50+
with pytest.raises(TmuxpPluginException, match=r'Incompatible.*') as exc_info:
5951
TmuxpVersionFailMinPlugin()
60-
assert False
61-
except TmuxpPluginException as error:
62-
assert 'Incompatible' in error.__str__()
52+
assert 'tmuxp-min-version-fail' in str(exc_info.value)
6353

6454

6555
def test_tmuxp_version_fail_max():
66-
try:
56+
with pytest.raises(TmuxpPluginException, match=r'Incompatible.*') as exc_info:
6757
TmuxpVersionFailMaxPlugin()
68-
assert False
69-
except TmuxpPluginException as error:
70-
assert 'Incompatible' in error.__str__()
58+
assert 'tmuxp-max-version-fail' in str(exc_info.value)
7159

7260

7361
def test_tmuxp_version_fail_incompatible():
74-
try:
62+
with pytest.raises(TmuxpPluginException, match=r'Incompatible.*') as exc_info:
7563
TmuxpVersionFailIncompatiblePlugin()
76-
assert False
77-
except TmuxpPluginException as error:
78-
assert 'Incompatible' in error.__str__()
64+
assert 'tmuxp-incompatible-version-fail' in str(exc_info.value)
7965

8066

8167
def test_libtmux_version_fail_min():
82-
try:
68+
with pytest.raises(TmuxpPluginException, match=r'Incompatible.*') as exc_info:
8369
LibtmuxVersionFailMinPlugin()
84-
assert False
85-
except TmuxpPluginException as error:
86-
assert 'Incompatible' in error.__str__()
70+
assert 'libtmux-min-version-fail' in str(exc_info.value)
8771

8872

8973
def test_libtmux_version_fail_max():
90-
try:
74+
with pytest.raises(TmuxpPluginException, match=r'Incompatible.*') as exc_info:
9175
LibtmuxVersionFailMaxPlugin()
92-
assert False
93-
except TmuxpPluginException as error:
94-
assert 'Incompatible' in error.__str__()
76+
assert 'libtmux-max-version-fail' in str(exc_info.value)
9577

9678

9779
def test_libtmux_version_fail_incompatible():
98-
try:
80+
with pytest.raises(TmuxpPluginException, match=r'Incompatible.*') as exc_info:
9981
LibtmuxVersionFailIncompatiblePlugin()
100-
assert False
101-
except TmuxpPluginException as error:
102-
assert 'Incompatible' in error.__str__()
82+
assert 'libtmux-incompatible-version-fail' in str(exc_info.value)

0 commit comments

Comments
 (0)