Ejemplo n.º 1
0
 def test_simple_resume_suspend(self, tmpfile):
     with saved_fd(1):
         cap = capture.FDCapture(1)
         cap.start()
         data = tobytes("hello")
         os.write(1, data)
         sys.stdout.write("whatever")
         s = cap.snap()
         assert s == "hellowhatever"
         cap.suspend()
         os.write(1, tobytes("world"))
         sys.stdout.write("qlwkej")
         assert not cap.snap()
         cap.resume()
         os.write(1, tobytes("but now"))
         sys.stdout.write(" yes\n")
         s = cap.snap()
         assert s == "but now yes\n"
         cap.suspend()
         cap.done()
         pytest.raises(AttributeError, cap.suspend)
Ejemplo n.º 2
0
 def test_stdin(self, tmpfile):
     cap = capture.FDCapture(0)
     cap.start()
     x = os.read(0, 100).strip()
     cap.done()
     assert x == tobytes('')
Ejemplo n.º 3
0
 def test_simple_fail_second_start(self, tmpfile):
     fd = tmpfile.fileno()
     cap = capture.FDCapture(fd)
     cap.done()
     pytest.raises(ValueError, cap.start)
Ejemplo n.º 4
0
 def test_stdin(self):
     cap = capture.FDCapture(0)
     cap.start()
     x = os.read(0, 100).strip()
     cap.done()
     assert x == b""
Ejemplo n.º 5
0
def StdCaptureFD(out: bool = True, err: bool = True, in_: bool = True) -> MultiCapture:
    return capture.MultiCapture(
        in_=capture.FDCapture(0) if in_ else None,
        out=capture.FDCapture(1) if out else None,
        err=capture.FDCapture(2) if err else None,
    )