mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Add py::print() function
Replicates Python API including keyword arguments.
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user