Skip to content

Commit 7df1b3c

Browse files
committed
move more tests (util, workspacebuilder) to py.test func
1 parent f877bae commit 7df1b3c

File tree

3 files changed

+495
-567
lines changed

3 files changed

+495
-567
lines changed

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ def server():
2020

2121

2222
@pytest.fixture(scope='function')
23-
def session(server):
23+
def session(request, server):
2424
t = server
2525
session_name = 'tmuxp'
26+
2627
if not t.has_session(session_name):
2728
t.cmd('new-session', '-d', '-s', session_name)
2829

@@ -61,6 +62,10 @@ def session(server):
6162
assert TEST_SESSION_NAME == session.get('session_name')
6263
assert TEST_SESSION_NAME != 'tmuxp'
6364

65+
def fin():
66+
t.kill_server()
67+
request.addfinalizer(fin)
68+
6469
return session
6570

6671

tests/test_util.py

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,86 +18,84 @@
1818
from tmuxp.exc import BeforeLoadScriptError, BeforeLoadScriptNotExists
1919
from tmuxp.util import has_required_tmux_version, run_before_script
2020

21-
from .helpers import TestCase, TmuxTestCase, fixtures_dir, stdouts
21+
from .helpers import fixtures_dir
2222

2323
logger = logging.getLogger(__name__)
2424

2525
version_regex = re.compile(r'[0-9]\.[0-9]')
2626

2727

28-
class TmuxVersionTest(TmuxTestCase):
29-
28+
def test_no_arg_uses_tmux_version():
3029
"""Test the :meth:`has_required_tmux_version`."""
30+
result = has_required_tmux_version()
31+
assert version_regex.match(result) is not None
3132

32-
def test_no_arg_uses_tmux_version(self):
33-
result = has_required_tmux_version()
34-
assert version_regex.match(result) is not None
35-
36-
def test_ignores_letter_versions(self):
37-
"""Ignore letters such as 1.8b.
3833

39-
See ticket https://github.com/tony/tmuxp/issues/55.
34+
def test_ignores_letter_versions():
35+
"""Ignore letters such as 1.8b.
4036
41-
In version 0.1.7 this is adjusted to use LooseVersion, in order to
42-
allow letters.
37+
See ticket https://github.com/tony/tmuxp/issues/55.
4338
44-
"""
45-
result = has_required_tmux_version('1.9a')
46-
assert version_regex.match(result) is not None
39+
In version 0.1.7 this is adjusted to use LooseVersion, in order to
40+
allow letters.
4741
48-
result = has_required_tmux_version('1.8a')
49-
assert result == r'1.8'
42+
"""
43+
result = has_required_tmux_version('1.9a')
44+
assert version_regex.match(result) is not None
5045

51-
def test_error_version_less_1_7(self):
52-
with pytest.raises(exc.TmuxpException) as excinfo:
53-
has_required_tmux_version('1.7')
54-
excinfo.match(r'tmuxp only supports')
46+
result = has_required_tmux_version('1.8a')
47+
assert result == r'1.8'
5548

56-
with pytest.raises(exc.TmuxpException) as excinfo:
57-
has_required_tmux_version('1.6a')
5849

59-
excinfo.match(r'tmuxp only supports')
50+
def test_error_version_less_1_7():
51+
with pytest.raises(exc.TmuxpException) as excinfo:
52+
has_required_tmux_version('1.7')
53+
excinfo.match(r'tmuxp only supports')
6054

61-
has_required_tmux_version('1.9a')
55+
with pytest.raises(exc.TmuxpException) as excinfo:
56+
has_required_tmux_version('1.6a')
6257

58+
excinfo.match(r'tmuxp only supports')
6359

64-
class RunBeforeScript(TestCase):
60+
has_required_tmux_version('1.9a')
6561

66-
def test_raise_BeforeLoadScriptNotExists_if_not_exists(self):
67-
script_file = os.path.join(fixtures_dir, 'script_noexists.sh')
6862

69-
with pytest.raises(BeforeLoadScriptNotExists):
70-
run_before_script(script_file)
63+
def test_raise_BeforeLoadScriptNotExists_if_not_exists():
64+
script_file = os.path.join(fixtures_dir, 'script_noexists.sh')
7165

72-
with pytest.raises(OSError):
73-
run_before_script(script_file)
66+
with pytest.raises(BeforeLoadScriptNotExists):
67+
run_before_script(script_file)
7468

75-
def test_raise_BeforeLoadScriptError_if_retcode(self):
76-
script_file = os.path.join(fixtures_dir, 'script_failed.sh')
69+
with pytest.raises(OSError):
70+
run_before_script(script_file)
7771

78-
with pytest.raises(BeforeLoadScriptError):
79-
run_before_script(script_file)
8072

81-
@stdouts
82-
def test_return_stdout_if_ok(self, stdout, stderr):
83-
script_file = os.path.join(fixtures_dir, 'script_complete.sh')
73+
def test_raise_BeforeLoadScriptError_if_retcode():
74+
script_file = os.path.join(fixtures_dir, 'script_failed.sh')
8475

76+
with pytest.raises(BeforeLoadScriptError):
8577
run_before_script(script_file)
86-
assert 'hello' in stdout.getvalue()
8778

8879

89-
class BeforeLoadScriptErrorTestCase(TestCase):
80+
def test_return_stdout_if_ok(capsys):
81+
script_file = os.path.join(fixtures_dir, 'script_complete.sh')
9082

91-
def test_returncode(self):
92-
script_file = os.path.join(fixtures_dir, 'script_failed.sh')
83+
run_before_script(script_file)
84+
out, err = capsys.readouterr()
85+
assert 'hello' in out
9386

94-
with pytest.raises(exc.BeforeLoadScriptError) as excinfo:
95-
run_before_script(script_file)
96-
assert excinfo.match(r'113')
9787

98-
def test_returns_stderr_messages(self):
99-
script_file = os.path.join(fixtures_dir, 'script_failed.sh')
88+
def test_beforeload_returncode():
89+
script_file = os.path.join(fixtures_dir, 'script_failed.sh')
10090

101-
with pytest.raises(exc.BeforeLoadScriptError) as excinfo:
102-
run_before_script(script_file)
103-
assert excinfo.match(r'failed with returncode')
91+
with pytest.raises(exc.BeforeLoadScriptError) as excinfo:
92+
run_before_script(script_file)
93+
assert excinfo.match(r'113')
94+
95+
96+
def test_beforeload_returns_stderr_messages():
97+
script_file = os.path.join(fixtures_dir, 'script_failed.sh')
98+
99+
with pytest.raises(exc.BeforeLoadScriptError) as excinfo:
100+
run_before_script(script_file)
101+
assert excinfo.match(r'failed with returncode')

0 commit comments

Comments
 (0)