未验证 提交 de33a8b0 编写于 作者: A Amador Pahim

Merge branch 'clebergnu-encoding_test_fix_v2'

Signed-off-by: NAmador Pahim <apahim@redhat.com>
......@@ -322,18 +322,18 @@ class CmdResult(object):
@property
def stdout_text(self):
if isinstance(self.stdout, string_types):
return self.stdout
if hasattr(self.stdout, 'decode'):
return self.stdout.decode(self.encoding)
if isinstance(self.stdout, string_types):
return self.stdout
raise TypeError("Unable to decode stdout into a string-like type")
@property
def stderr_text(self):
if isinstance(self.stderr, string_types):
return self.stderr
if hasattr(self.stderr, 'decode'):
return self.stderr.decode(self.encoding)
if isinstance(self.stderr, string_types):
return self.stderr
raise TypeError("Unable to decode stderr into a string-like type")
def __repr__(self):
......
......@@ -258,9 +258,16 @@ class TestProcessRun(unittest.TestCase):
# but the behavior is exactly the same as if shell binary
# produced unicode
text = u"Avok\xe1do"
result = process.run("%s %s" % (ECHO_CMD, text), encoding='utf-8')
self.assertEqual(result.stdout, text.encode('utf-8') + b'\n')
self.assertEqual(result.stdout_text, text + '\n')
# Even though code point used is "LATIN SMALL LETTER A WITH ACUTE"
# (http://unicode.scarfboy.com/?s=u%2B00e1) when encoded to proper
# utf-8, it becomes two bytes because it is >= 0x80
# See https://en.wikipedia.org/wiki/UTF-8
encoded_text = b'Avok\xc3\xa1do'
self.assertEqual(text.encode('utf-8'), encoded_text)
self.assertEqual(encoded_text.decode('utf-8'), text)
result = process.run("%s -n %s" % (ECHO_CMD, text), encoding='utf-8')
self.assertEqual(result.stdout, encoded_text)
self.assertEqual(result.stdout_text, text)
class MiscProcessTests(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册