aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/pybind11/tests/test_iostream.py
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/pybind11/tests/test_iostream.py')
-rw-r--r--3rdparty/pybind11/tests/test_iostream.py155
1 files changed, 116 insertions, 39 deletions
diff --git a/3rdparty/pybind11/tests/test_iostream.py b/3rdparty/pybind11/tests/test_iostream.py
index 506db42e..5bbdf695 100644
--- a/3rdparty/pybind11/tests/test_iostream.py
+++ b/3rdparty/pybind11/tests/test_iostream.py
@@ -1,43 +1,7 @@
-# -*- coding: utf-8 -*-
+from contextlib import redirect_stderr, redirect_stdout
+from io import StringIO
+
from pybind11_tests import iostream as m
-import sys
-
-from contextlib import contextmanager
-
-try:
- # Python 3
- from io import StringIO
-except ImportError:
- # Python 2
- try:
- from cStringIO import StringIO
- except ImportError:
- from StringIO import StringIO
-
-try:
- # Python 3.4
- from contextlib import redirect_stdout
-except ImportError:
-
- @contextmanager
- def redirect_stdout(target):
- original = sys.stdout
- sys.stdout = target
- yield
- sys.stdout = original
-
-
-try:
- # Python 3.5
- from contextlib import redirect_stderr
-except ImportError:
-
- @contextmanager
- def redirect_stderr(target):
- original = sys.stderr
- sys.stderr = target
- yield
- sys.stderr = original
def test_captured(capsys):
@@ -69,6 +33,96 @@ def test_captured_large_string(capsys):
assert stderr == ""
+def test_captured_utf8_2byte_offset0(capsys):
+ msg = "\u07FF"
+ msg = "" + msg * (1024 // len(msg) + 1)
+
+ m.captured_output_default(msg)
+ stdout, stderr = capsys.readouterr()
+ assert stdout == msg
+ assert stderr == ""
+
+
+def test_captured_utf8_2byte_offset1(capsys):
+ msg = "\u07FF"
+ msg = "1" + msg * (1024 // len(msg) + 1)
+
+ m.captured_output_default(msg)
+ stdout, stderr = capsys.readouterr()
+ assert stdout == msg
+ assert stderr == ""
+
+
+def test_captured_utf8_3byte_offset0(capsys):
+ msg = "\uFFFF"
+ msg = "" + msg * (1024 // len(msg) + 1)
+
+ m.captured_output_default(msg)
+ stdout, stderr = capsys.readouterr()
+ assert stdout == msg
+ assert stderr == ""
+
+
+def test_captured_utf8_3byte_offset1(capsys):
+ msg = "\uFFFF"
+ msg = "1" + msg * (1024 // len(msg) + 1)
+
+ m.captured_output_default(msg)
+ stdout, stderr = capsys.readouterr()
+ assert stdout == msg
+ assert stderr == ""
+
+
+def test_captured_utf8_3byte_offset2(capsys):
+ msg = "\uFFFF"
+ msg = "12" + msg * (1024 // len(msg) + 1)
+
+ m.captured_output_default(msg)
+ stdout, stderr = capsys.readouterr()
+ assert stdout == msg
+ assert stderr == ""
+
+
+def test_captured_utf8_4byte_offset0(capsys):
+ msg = "\U0010FFFF"
+ msg = "" + msg * (1024 // len(msg) + 1)
+
+ m.captured_output_default(msg)
+ stdout, stderr = capsys.readouterr()
+ assert stdout == msg
+ assert stderr == ""
+
+
+def test_captured_utf8_4byte_offset1(capsys):
+ msg = "\U0010FFFF"
+ msg = "1" + msg * (1024 // len(msg) + 1)
+
+ m.captured_output_default(msg)
+ stdout, stderr = capsys.readouterr()
+ assert stdout == msg
+ assert stderr == ""
+
+
+def test_captured_utf8_4byte_offset2(capsys):
+ msg = "\U0010FFFF"
+ msg = "12" + msg * (1024 // len(msg) + 1)
+
+ m.captured_output_default(msg)
+ stdout, stderr = capsys.readouterr()
+ assert stdout == msg
+ assert stderr == ""
+
+
+def test_captured_utf8_4byte_offset3(capsys):
+ msg = "\U0010FFFF"
+ msg = "123" + msg * (1024 // len(msg) + 1)
+
+ m.captured_output_default(msg)
+ stdout, stderr = capsys.readouterr()
+ assert stdout == msg
+ assert stderr == ""
+
+
def test_guard_capture(capsys):
msg = "I've been redirected to Python, I hope!"
m.guard_output(msg)
@@ -216,3 +270,26 @@ def test_redirect_both(capfd):
assert stderr == ""
assert stream.getvalue() == msg
assert stream2.getvalue() == msg2
+
+
+def test_threading():
+ with m.ostream_redirect(stdout=True, stderr=False):
+ # start some threads
+ threads = []
+
+ # start some threads
+ for _j in range(20):
+ threads.append(m.TestThread())
+
+ # give the threads some time to fail
+ threads[0].sleep()
+
+ # stop all the threads
+ for t in threads:
+ t.stop()
+
+ for t in threads:
+ t.join()
+
+ # if a thread segfaults, we don't get here
+ assert True