Test BrokenPipe works as expected.
()
| 1005 | |
| 1006 | @pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") |
| 1007 | def test_brokenpipeerror() -> None: |
| 1008 | """Test BrokenPipe works as expected.""" |
| 1009 | which_py, which_head = (["which", cmd] for cmd in ("python", "head")) |
| 1010 | rich_cmd = "python -m rich".split() |
| 1011 | for cmd in [which_py, which_head, rich_cmd]: |
| 1012 | check = subprocess.run(cmd).returncode |
| 1013 | if check != 0: |
| 1014 | return # Only test on suitable Unix platforms |
| 1015 | head_cmd = "head -1".split() |
| 1016 | proc1 = subprocess.Popen(rich_cmd, stdout=subprocess.PIPE) |
| 1017 | proc2 = subprocess.Popen(head_cmd, stdin=proc1.stdout, stdout=subprocess.PIPE) |
| 1018 | proc1.stdout.close() |
| 1019 | output, _ = proc2.communicate() |
| 1020 | proc1.wait() |
| 1021 | proc2.wait() |
| 1022 | assert proc1.returncode == 1 |
| 1023 | assert proc2.returncode == 0 |
| 1024 | |
| 1025 | |
| 1026 | def test_capture_and_record() -> None: |