|
18 | 18 | from tmuxp.exc import BeforeLoadScriptError, BeforeLoadScriptNotExists |
19 | 19 | from tmuxp.util import has_required_tmux_version, run_before_script |
20 | 20 |
|
21 | | -from .helpers import TestCase, TmuxTestCase, fixtures_dir, stdouts |
| 21 | +from .helpers import fixtures_dir |
22 | 22 |
|
23 | 23 | logger = logging.getLogger(__name__) |
24 | 24 |
|
25 | 25 | version_regex = re.compile(r'[0-9]\.[0-9]') |
26 | 26 |
|
27 | 27 |
|
28 | | -class TmuxVersionTest(TmuxTestCase): |
29 | | - |
| 28 | +def test_no_arg_uses_tmux_version(): |
30 | 29 | """Test the :meth:`has_required_tmux_version`.""" |
| 30 | + result = has_required_tmux_version() |
| 31 | + assert version_regex.match(result) is not None |
31 | 32 |
|
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. |
38 | 33 |
|
39 | | - See ticket https://github.com/tony/tmuxp/issues/55. |
| 34 | +def test_ignores_letter_versions(): |
| 35 | + """Ignore letters such as 1.8b. |
40 | 36 |
|
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. |
43 | 38 |
|
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. |
47 | 41 |
|
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 |
50 | 45 |
|
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' |
55 | 48 |
|
56 | | - with pytest.raises(exc.TmuxpException) as excinfo: |
57 | | - has_required_tmux_version('1.6a') |
58 | 49 |
|
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') |
60 | 54 |
|
61 | | - has_required_tmux_version('1.9a') |
| 55 | + with pytest.raises(exc.TmuxpException) as excinfo: |
| 56 | + has_required_tmux_version('1.6a') |
62 | 57 |
|
| 58 | + excinfo.match(r'tmuxp only supports') |
63 | 59 |
|
64 | | -class RunBeforeScript(TestCase): |
| 60 | + has_required_tmux_version('1.9a') |
65 | 61 |
|
66 | | - def test_raise_BeforeLoadScriptNotExists_if_not_exists(self): |
67 | | - script_file = os.path.join(fixtures_dir, 'script_noexists.sh') |
68 | 62 |
|
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') |
71 | 65 |
|
72 | | - with pytest.raises(OSError): |
73 | | - run_before_script(script_file) |
| 66 | + with pytest.raises(BeforeLoadScriptNotExists): |
| 67 | + run_before_script(script_file) |
74 | 68 |
|
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) |
77 | 71 |
|
78 | | - with pytest.raises(BeforeLoadScriptError): |
79 | | - run_before_script(script_file) |
80 | 72 |
|
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') |
84 | 75 |
|
| 76 | + with pytest.raises(BeforeLoadScriptError): |
85 | 77 | run_before_script(script_file) |
86 | | - assert 'hello' in stdout.getvalue() |
87 | 78 |
|
88 | 79 |
|
89 | | -class BeforeLoadScriptErrorTestCase(TestCase): |
| 80 | +def test_return_stdout_if_ok(capsys): |
| 81 | + script_file = os.path.join(fixtures_dir, 'script_complete.sh') |
90 | 82 |
|
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 |
93 | 86 |
|
94 | | - with pytest.raises(exc.BeforeLoadScriptError) as excinfo: |
95 | | - run_before_script(script_file) |
96 | | - assert excinfo.match(r'113') |
97 | 87 |
|
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') |
100 | 90 |
|
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