worker: add test for invalid utf-8 output

This commit is contained in:
Volker Braun
2019-05-03 09:50:16 +02:00
parent bcf21933ba
commit 0d87c2de80
2 changed files with 19 additions and 1 deletions

View File

@@ -177,6 +177,23 @@ class TestRunProcess(BasedirMixin, unittest.TestCase):
self.assertTrue({'stdout': u"\N{SNOWMAN}"} in b.updates)
self.assertTrue({'rc': 0} in b.updates, b.show())
@defer.inlineCallbacks
def testInvalidUTF8(self):
b = FakeWorkerForBuilder(self.basedir)
b.unicode_encoding = "utf-8"
s = runprocess.RunProcess(
b, stderrCommand("hello"), self.basedir, sendStderr=True)
pp = runprocess.RunProcessPP(s)
INVALID_UTF8 = b"\xff"
with self.assertRaises(UnicodeDecodeError):
INVALID_UTF8.decode('utf-8')
pp.outReceived(INVALID_UTF8)
yield s.start()
stdout = [up['stdout'] for up in b.updates if 'stdout' in up][0]
# On Python < 2.7 bytes is used, on Python >= 2.7 unicode
self.assertIn(stdout, (b'\xef\xbf\xbd', u'\ufffd'))
self.assertTrue({'rc': 0} in b.updates, b.show())
@defer.inlineCallbacks
def testKeepStderr(self):
b = FakeWorkerForBuilder(self.basedir)

View File

@@ -4,7 +4,8 @@
# and then run "tox" from this directory.
[tox]
envlist = py24, py25, py26, py27
envlist = py24, py25, py26, py27, py35, py36, py37
[testenv]
deps = setuptools_trial
commands = python setup.py test