|
6 | 6 | Copyright 2018 Todd Leonhardt <todd.leonhardt@gmail.com> |
7 | 7 | Released under MIT license, see LICENSE file |
8 | 8 | """ |
| 9 | +import signal |
9 | 10 | import sys |
10 | 11 |
|
11 | 12 | import pytest |
@@ -216,3 +217,53 @@ def test_stdsim_pause_storage(stdout_sim): |
216 | 217 | stdout_sim.pause_storage = True |
217 | 218 | stdout_sim.buffer.write(b_str) |
218 | 219 | assert stdout_sim.getbytes() == b'' |
| 220 | + |
| 221 | + |
| 222 | +@pytest.fixture |
| 223 | +def pr_none(): |
| 224 | + import subprocess |
| 225 | + command = 'ls' |
| 226 | + if sys.platform.startswith('win'): |
| 227 | + command = 'dir' |
| 228 | + proc = subprocess.Popen([command], shell=True) |
| 229 | + pr = cu.ProcReader(proc, None, None) |
| 230 | + return pr |
| 231 | + |
| 232 | +def test_proc_reader_send_sigint(pr_none): |
| 233 | + assert pr_none._proc.poll() is None |
| 234 | + pr_none.send_sigint() |
| 235 | + pr_none.wait() |
| 236 | + ret_code = pr_none._proc.poll() |
| 237 | + if sys.platform.startswith('win'): |
| 238 | + assert ret_code is not None |
| 239 | + else: |
| 240 | + assert ret_code == -signal.SIGINT |
| 241 | + |
| 242 | +def test_proc_reader_terminate(pr_none): |
| 243 | + assert pr_none._proc.poll() is None |
| 244 | + pr_none.terminate() |
| 245 | + pr_none.wait() |
| 246 | + ret_code = pr_none._proc.poll() |
| 247 | + if sys.platform.startswith('win'): |
| 248 | + assert ret_code is not None |
| 249 | + else: |
| 250 | + assert ret_code == -signal.SIGTERM |
| 251 | + |
| 252 | +def test_proc_reader_wait(pr_none): |
| 253 | + assert pr_none._proc.poll() is None |
| 254 | + pr_none.wait() |
| 255 | + assert pr_none._proc.poll() == 0 |
| 256 | + |
| 257 | + |
| 258 | +@pytest.fixture |
| 259 | +def context_flag(): |
| 260 | + return cu.ContextFlag() |
| 261 | + |
| 262 | +def test_context_flag_bool(context_flag): |
| 263 | + assert not context_flag |
| 264 | + with context_flag: |
| 265 | + assert context_flag |
| 266 | + |
| 267 | +def test_context_flag_exit_err(context_flag): |
| 268 | + with pytest.raises(ValueError): |
| 269 | + context_flag.__exit__() |
0 commit comments