Add py::print() function

Replicates Python API including keyword arguments.
This commit is contained in:
Dean Moldovan
2016-08-29 18:03:34 +02:00
parent c743e1b1b4
commit 67990d9e19
4 changed files with 69 additions and 5 deletions

View File

@@ -68,18 +68,22 @@ class Capture(object):
def __init__(self, capfd):
self.capfd = capfd
self.out = ""
self.err = ""
def _flush_stdout(self):
def _flush(self):
"""Workaround for issues on Windows: to be removed after tests get py::print"""
sys.stdout.flush()
os.fsync(sys.stdout.fileno()) # make sure C++ output is also read
return self.capfd.readouterr()[0]
os.fsync(sys.stdout.fileno())
sys.stderr.flush()
os.fsync(sys.stderr.fileno())
return self.capfd.readouterr()
def __enter__(self):
self._flush_stdout()
self._flush()
return self
def __exit__(self, *_):
self.out = self._flush_stdout()
self.out, self.err = self._flush()
def __eq__(self, other):
a = Output(self.out)
@@ -100,6 +104,10 @@ class Capture(object):
def unordered(self):
return Unordered(self.out)
@property
def stderr(self):
return Output(self.err)
@pytest.fixture
def capture(capfd):