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
This commit is contained in:
@@ -12,7 +12,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import fixtures
|
import sys
|
||||||
|
|
||||||
|
import mock
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
import six
|
import six
|
||||||
import testtools
|
import testtools
|
||||||
@@ -30,12 +32,11 @@ class TestExceptions(testtools.TestCase):
|
|||||||
multibyte_unicode_string = u'\uff21\uff22\uff23'
|
multibyte_unicode_string = u'\uff21\uff22\uff23'
|
||||||
e = TestException(reason=multibyte_unicode_string)
|
e = TestException(reason=multibyte_unicode_string)
|
||||||
|
|
||||||
fixture = fixtures.StringStream('stdout')
|
with mock.patch.object(sys, 'stdout') as mock_stdout:
|
||||||
self.useFixture(fixture)
|
|
||||||
with fixtures.MonkeyPatch('sys.stdout', fixture.stream):
|
|
||||||
print(e)
|
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):
|
def test_exception_message_with_encoded_unicode(self):
|
||||||
class TestException(exceptions.NeutronException):
|
class TestException(exceptions.NeutronException):
|
||||||
|
Reference in New Issue
Block a user