/usr/lib/python2.7/dist-packages/PySPH-1.0a4.dev0-py2.7-linux-x86_64.egg/pysph/base/tests/test_capture_stream.py is in python-pysph 0~20160514.git91867dc-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import subprocess
import sys
import unittest
from pysph.base.capture_stream import CaptureMultipleStreams, CaptureStream
def write_stderr():
subprocess.call(
[sys.executable, "-S", "-s", "-c",
"import sys;sys.stderr.write('stderr')"]
)
def write_stdout():
subprocess.call(
[sys.executable, "-S", "-s", "-c",
"import sys;sys.stdout.write('stdout')"]
)
class TestCaptureStream(unittest.TestCase):
def test_that_stderr_is_captured_by_default(self):
# Given
# When
with CaptureStream() as stream:
write_stderr()
# Then
self.assertEqual(stream.get_output(), "stderr")
def test_that_stdout_can_be_captured(self):
# Given
# When
with CaptureStream(sys.stdout) as stream:
write_stdout()
# Then
self.assertEqual(stream.get_output(), "stdout")
def test_that_output_is_available_in_context_and_outside(self):
# Given
# When
with CaptureStream(sys.stderr) as stream:
write_stderr()
# Then
self.assertEqual(stream.get_output(), "stderr")
# Then
self.assertEqual(stream.get_output(), "stderr")
class TestCaptureMultipleStreams(unittest.TestCase):
def test_that_stdout_stderr_are_captured_by_default(self):
# Given
# When
with CaptureMultipleStreams() as stream:
write_stderr()
write_stdout()
# Then
outputs = stream.get_output()
self.assertEqual(outputs[0], "stdout")
self.assertEqual(outputs[1], "stderr")
def test_that_order_is_preserved(self):
# Given
# When
with CaptureMultipleStreams((sys.stderr, sys.stdout)) as stream:
write_stderr()
write_stdout()
# Then
outputs = stream.get_output()
self.assertEqual(outputs[0], "stderr")
self.assertEqual(outputs[1], "stdout")
if __name__ == '__main__':
unittest.main()
|