diff options
author | Tim Burke <tim.burke@gmail.com> | 2015-05-17 23:51:37 -0700 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2015-07-07 15:39:02 -0700 |
commit | cf0b6c03df5b014e8c21ffcb0fe92f58e11c7ae3 (patch) | |
tree | 6d3d02d39244773e2c23397b8310c9b95854c2c3 /tests/unit/test_multithreading.py | |
parent | 92b82777523b0858d6f20fc49ea60f7edebb2dca (diff) | |
download | python-swiftclient-cf0b6c03df5b014e8c21ffcb0fe92f58e11c7ae3.tar.gz |
Properly test raw writes in Python 3
Previously we were trying to test writing bytes in Python 3 using only
native (unicode) string objects. That doesn't test what we thought we
were testing.
Change-Id: I10a0a38143d7f7d850ab9a7005ad87f5d314c375
Diffstat (limited to 'tests/unit/test_multithreading.py')
-rw-r--r-- | tests/unit/test_multithreading.py | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/tests/unit/test_multithreading.py b/tests/unit/test_multithreading.py index 6597793..42abbbf 100644 --- a/tests/unit/test_multithreading.py +++ b/tests/unit/test_multithreading.py @@ -12,7 +12,6 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. - import sys import testtools import threading @@ -206,10 +205,12 @@ class TestOutputManager(testtools.TestCase): u'some raw bytes: \u062A\u062A'.encode('utf-8')) thread_manager.print_items([ - ('key', u'value'), - ('object', 'O\xcc\x88bject') + ('key', 'value'), + ('object', u'O\u0308bject'), ]) + thread_manager.print_raw(b'\xffugly\xffraw') + # Now we have a thread for error printing and a thread for # normal print messages self.assertEqual(starting_thread_count + 2, @@ -220,31 +221,23 @@ class TestOutputManager(testtools.TestCase): if six.PY3: over_the = "over the '\u062a\u062a'\n" - # The CaptureStreamBuffer just encodes all bytes written to it by - # mapping chr over the byte string to produce a str. - raw_bytes = ''.join( - map(chr, u'some raw bytes: \u062A\u062A'.encode('utf-8')) - ) else: over_the = "over the u'\\u062a\\u062a'\n" # We write to the CaptureStream so no decoding is performed - raw_bytes = 'some raw bytes: \xd8\xaa\xd8\xaa' self.assertEqual(''.join([ 'one-argument\n', 'one fish, 88 fish\n', 'some\n', 'where\n', - over_the, raw_bytes, + over_the, + u'some raw bytes: \u062a\u062a', ' key: value\n', - ' object: O\xcc\x88bject\n' - ]), out_stream.getvalue()) + u' object: O\u0308bject\n' + ]).encode('utf8') + b'\xffugly\xffraw', out_stream.getvalue()) - first_item = u'I have 99 problems, but a \u062A\u062A is not one\n' - if six.PY2: - first_item = first_item.encode('utf8') self.assertEqual(''.join([ - first_item, + u'I have 99 problems, but a \u062A\u062A is not one\n', 'one-error-argument\n', 'Sometimes\n', '3.1% just\n', 'does not\n', 'work!\n' - ]), err_stream.getvalue()) + ]), err_stream.getvalue().decode('utf8')) self.assertEqual(3, thread_manager.error_count) |