diff options
author | Rodolfo Alonso Hernandez <ralonsoh@redhat.com> | 2020-01-10 18:54:28 +0000 |
---|---|---|
committer | Rodolfo Alonso Hernandez <ralonsoh@redhat.com> | 2020-01-10 18:57:25 +0000 |
commit | a363edd761e2c99bae6d4492d0ca44a404e5d904 (patch) | |
tree | 3b4bfc02b087f8ec591bee991679ef251fcea8e6 /neutronclient/tests | |
parent | 29043825e7e19b4f32f3998ea95419ad2429cd14 (diff) | |
download | python-neutronclient-a363edd761e2c99bae6d4492d0ca44a404e5d904.tar.gz |
Avoid py36 error when printing unicode chars in a stream
The IOStream was not able to encode characters out of range 128:
"UnicodeEncodeError: 'ascii' codec can't encode characters in
position 19-21: ordinal not in range(128)"
Change-Id: Ic95396a5cf73c49d332928857dc064819a6d7ea6
Closes-Bug: #1858421
Diffstat (limited to 'neutronclient/tests')
-rw-r--r-- | neutronclient/tests/unit/test_exceptions.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/neutronclient/tests/unit/test_exceptions.py b/neutronclient/tests/unit/test_exceptions.py index 9174287..aefc24c 100644 --- a/neutronclient/tests/unit/test_exceptions.py +++ b/neutronclient/tests/unit/test_exceptions.py @@ -12,7 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -import fixtures +import sys + +import mock from oslo_utils import encodeutils import six import testtools @@ -30,12 +32,11 @@ class TestExceptions(testtools.TestCase): multibyte_unicode_string = u'\uff21\uff22\uff23' e = TestException(reason=multibyte_unicode_string) - fixture = fixtures.StringStream('stdout') - self.useFixture(fixture) - with fixtures.MonkeyPatch('sys.stdout', fixture.stream): + with mock.patch.object(sys, 'stdout') as mock_stdout: print(e) - self.assertEqual('Exception with %s' % multibyte_unicode_string, - fixture.getDetails().get('stdout').as_text()) + + exc_str = 'Exception with %s' % multibyte_unicode_string + mock_stdout.assert_has_calls([mock.call.write(exc_str)]) def test_exception_message_with_encoded_unicode(self): class TestException(exceptions.NeutronException): |