diff options
| author | Robert Collins <robertc@robertcollins.net> | 2017-10-03 20:24:49 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-03 20:24:49 +1300 |
| commit | 12b024344e757949e9928c5e682b7b09fa220b37 (patch) | |
| tree | 5cea6f3614363d2d12ccd980f02fdceae4223073 /python/subunit/tests | |
| parent | 7149380ff9a4f77f523b4b82e88b22c4e55a77a6 (diff) | |
| parent | df2c69b59978bd5ba90db298bbae08bbd4e53595 (diff) | |
| download | subunit-git-12b024344e757949e9928c5e682b7b09fa220b37.tar.gz | |
Merge pull request #25 from mtreinish/add-value-error-to-write-only-stream-check
Check for ValueError in write only check in _unwrap_text()
Diffstat (limited to 'python/subunit/tests')
| -rw-r--r-- | python/subunit/tests/test_test_protocol.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index f3cd0e3..7427b12 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -15,8 +15,11 @@ # import datetime +import io import unittest2 as unittest import os +import sys +import tempfile from testtools import PlaceHolder, skipIf, TestCase, TestResult from testtools.compat import _b, _u, BytesIO @@ -52,6 +55,44 @@ def details_to_str(details): return TestResult()._err_details_to_string(None, details=details) +class TestHelpers(TestCase): + def test__unwrap_text_file_read_mode(self): + fd, file_path = tempfile.mkstemp() + self.addCleanup(os.remove, file_path) + fake_file = os.fdopen(fd, 'r') + if sys.version_info > (3, 0): + self.assertEqual(fake_file.buffer, + subunit._unwrap_text(fake_file)) + else: + self.assertEqual(fake_file, subunit._unwrap_text(fake_file)) + + def test__unwrap_text_file_write_mode(self): + fd, file_path = tempfile.mkstemp() + self.addCleanup(os.remove, file_path) + fake_file = os.fdopen(fd, 'w') + if sys.version_info > (3, 0): + self.assertEqual(fake_file.buffer, + subunit._unwrap_text(fake_file)) + else: + self.assertEqual(fake_file, subunit._unwrap_text(fake_file)) + + def test__unwrap_text_fileIO_read_mode(self): + fd, file_path = tempfile.mkstemp() + self.addCleanup(os.remove, file_path) + fake_file = io.FileIO(file_path, 'r') + self.assertEqual(fake_file, subunit._unwrap_text(fake_file)) + + def test__unwrap_text_fileIO_write_mode(self): + fd, file_path = tempfile.mkstemp() + self.addCleanup(os.remove, file_path) + fake_file = io.FileIO(file_path, 'w') + self.assertEqual(fake_file, subunit._unwrap_text(fake_file)) + + def test__unwrap_text_BytesIO(self): + fake_stream = io.BytesIO() + self.assertEqual(fake_stream, subunit._unwrap_text(fake_stream)) + + class TestTestImports(unittest.TestCase): def test_imports(self): |
