|
| 1 | +import unittest |
| 2 | + |
1 | 3 | import testlib |
2 | 4 |
|
3 | 5 | import stdio_checks |
4 | 6 |
|
5 | 7 |
|
6 | | -class StdIOTest(testlib.RouterMixin, testlib.TestCase): |
| 8 | +class StdIOMixin(testlib.RouterMixin): |
7 | 9 | """ |
8 | 10 | Test that stdin, stdout, and stderr conform to common expectations, |
9 | 11 | such as blocking IO. |
10 | 12 | """ |
11 | | - def test_can_write_stdout_1_mib(self): |
| 13 | + def check_can_write_stdout_1_mib(self, context): |
12 | 14 | """ |
13 | 15 | Writing to stdout should not raise EAGAIN. Regression test for |
14 | 16 | https://github.com/mitogen-hq/mitogen/issues/712. |
15 | 17 | """ |
16 | 18 | size = 1 * 2**20 |
17 | | - context = self.router.local() |
18 | 19 | nwritten = context.call(stdio_checks.shout_stdout, size) |
19 | 20 | self.assertEqual(nwritten, size) |
20 | 21 |
|
21 | | - def test_stdio_is_blocking(self): |
22 | | - context = self.router.local() |
| 22 | + def check_stdio_is_blocking(self, context): |
23 | 23 | stdin_blocking, stdout_blocking, stderr_blocking = context.call( |
24 | 24 | stdio_checks.stdio_is_blocking, |
25 | 25 | ) |
26 | 26 | self.assertTrue(stdin_blocking) |
27 | 27 | self.assertTrue(stdout_blocking) |
28 | 28 | self.assertTrue(stderr_blocking) |
| 29 | + |
| 30 | + |
| 31 | +class LocalTest(StdIOMixin, testlib.TestCase): |
| 32 | + def test_can_write_stdout_1_mib(self): |
| 33 | + self.check_can_write_stdout_1_mib(self.router.local()) |
| 34 | + |
| 35 | + def test_stdio_is_blocking(self): |
| 36 | + self.check_stdio_is_blocking(self.router.local()) |
| 37 | + |
| 38 | + |
| 39 | +class SudoTest(StdIOMixin, testlib.TestCase): |
| 40 | + @unittest.skipIf(not testlib.have_sudo_nopassword(), 'Needs passwordless sudo') |
| 41 | + def test_can_write_stdout_1_mib(self): |
| 42 | + self.check_can_write_stdout_1_mib(self.router.sudo()) |
| 43 | + |
| 44 | + @unittest.skipIf(not testlib.have_sudo_nopassword(), 'Needs passwordless sudo') |
| 45 | + def test_stdio_is_blocking(self): |
| 46 | + self.check_stdio_is_blocking(self.router.sudo()) |
0 commit comments