| 1013 | assert stmp == data2 |
| 1014 | |
| 1015 | def test_simple_resume_suspend(self) -> None: |
| 1016 | with saved_fd(1): |
| 1017 | cap = capture.FDCapture(1) |
| 1018 | cap.start() |
| 1019 | data = b"hello" |
| 1020 | os.write(1, data) |
| 1021 | sys.stdout.write("whatever") |
| 1022 | s = cap.snap() |
| 1023 | assert s == "hellowhatever" |
| 1024 | cap.suspend() |
| 1025 | os.write(1, b"world") |
| 1026 | sys.stdout.write("qlwkej") |
| 1027 | assert not cap.snap() |
| 1028 | cap.resume() |
| 1029 | os.write(1, b"but now") |
| 1030 | sys.stdout.write(" yes\n") |
| 1031 | s = cap.snap() |
| 1032 | assert s == "but now yes\n" |
| 1033 | cap.suspend() |
| 1034 | cap.done() |
| 1035 | pytest.raises(AssertionError, cap.suspend) |
| 1036 | |
| 1037 | assert repr(cap) == ( |
| 1038 | "<FDCapture 1 oldfd={} _state='done' tmpfile={!r}>".format( |
| 1039 | cap.targetfd_save, cap.tmpfile |
| 1040 | ) |
| 1041 | ) |
| 1042 | # Should not crash with missing "_old". |
| 1043 | assert repr(cap.syscapture) == ( |
| 1044 | "<SysCapture stdout _old=<UNSET> _state='done' tmpfile={!r}>".format( |
| 1045 | cap.syscapture.tmpfile |
| 1046 | ) |
| 1047 | ) |
| 1048 | |
| 1049 | def test_capfd_sys_stdout_mode(self, capfd) -> None: |
| 1050 | assert "b" not in sys.stdout.mode |