|
3 | 3 | import shutil |
4 | 4 | import tempfile |
5 | 5 |
|
| 6 | +if sys.version_info[0] < 3: |
| 7 | + from io import BytesIO as io_mock |
| 8 | +else: |
| 9 | + from io import StringIO as io_mock |
| 10 | + |
6 | 11 | try: |
7 | 12 | from unittest.mock import patch |
8 | 13 | except ImportError: |
@@ -97,7 +102,8 @@ def test_pdb_off_and_wait_on_arguments(self, watch_callee): |
97 | 102 | watch_callee.call_args[1]["pytest_args"]) |
98 | 103 |
|
99 | 104 |
|
100 | | -@patch("pytest_watch.command.merge_config", side_effect=lambda *args, **kwargs: True) |
| 105 | +@patch("pytest_watch.command.merge_config", |
| 106 | + side_effect=lambda *args, **kwargs: True) |
101 | 107 | @patch("pytest_watch.command.watch", side_effect=lambda *args, **kwargs: 0) |
102 | 108 | class TestConfigArgument(unittest.TestCase): |
103 | 109 | def test_default_config(self, watch_callee, merge_config_callee): |
@@ -226,20 +232,32 @@ def test_default_spool_value(self, watch_callee): |
226 | 232 | self.assertEqual(200, watch_callee.call_args[1]["spool"]) |
227 | 233 | watch_callee.assert_called_once() |
228 | 234 |
|
229 | | - def test_cause_error_for_negative_spool_values(self, watch_callee): |
230 | | - self.assertEqual(2, main("--spool -1".split())) |
| 235 | + def _assert_spool_error(self, watch_callee, value, err): |
| 236 | + with patch("pytest_watch.command.sys.stderr", new=io_mock()) as out: |
| 237 | + self.assertEqual(2, main(["--spool", value])) |
| 238 | + assert err == out.getvalue(), \ |
| 239 | + "Status code for invalid 'spool' argument should be 2" |
231 | 240 | watch_callee.assert_not_called() |
232 | 241 |
|
| 242 | + def test_cause_error_for_negative_spool_values(self, watch_callee): |
| 243 | + err = "Error: Spool value(--spool -1) must be positive integer\n" |
| 244 | + self._assert_spool_error(watch_callee, value="-1", err=err) |
| 245 | + |
233 | 246 | def test_cause_error_for_invalid_spool_values(self, watch_callee): |
234 | | - self.assertEquals(2, main("--spool abc".split()), |
235 | | - "Status code for not integer 'spool' " \ |
236 | | - "argument should be 2") |
237 | | - self.assertEquals(2, main("--spool @".split()), |
238 | | - "Status code for not integer 'spool' " \ |
239 | | - "argument should be 2") |
240 | | - self.assertEquals(2, main("--spool []".split()), |
241 | | - "Status code for not integer 'spool' " \ |
242 | | - "argument should be 2") |
| 247 | + value = "abc" |
| 248 | + self._assert_spool_error(watch_callee, value=value, |
| 249 | + err="Error: Spool (--spool {}) must be" \ |
| 250 | + " an integer.\n".format(value)) |
| 251 | + |
| 252 | + value = "@" |
| 253 | + self._assert_spool_error(watch_callee, value=value, |
| 254 | + err="Error: Spool (--spool {}) must be" \ |
| 255 | + " an integer.\n".format(value)) |
| 256 | + |
| 257 | + value = "[]" |
| 258 | + self._assert_spool_error(watch_callee, value=value, |
| 259 | + err="Error: Spool (--spool {}) must be" \ |
| 260 | + " an integer.\n".format(value)) |
243 | 261 |
|
244 | 262 |
|
245 | 263 | @patch("pytest_watch.command.watch", side_effect=lambda *args, **kwargs: 0) |
|
0 commit comments