py3: decode stdout from backgrounded servers
Otherwise, when we go to print() it, we get a bunch of b"" strings. Change-Id: If62da0b4b34b9d1396b5838bf79ff494679f1ae3
This commit is contained in:
parent
489a35db82
commit
ad7f7da32d
@ -22,6 +22,7 @@ import signal
|
|||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
import six
|
||||||
from swift import gettext_ as _
|
from swift import gettext_ as _
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
@ -720,6 +721,8 @@ class Server(object):
|
|||||||
else:
|
else:
|
||||||
output = proc.stdout.read()
|
output = proc.stdout.read()
|
||||||
proc.stdout.close()
|
proc.stdout.close()
|
||||||
|
if not six.PY2:
|
||||||
|
output = output.decode('utf8', 'backslashreplace')
|
||||||
|
|
||||||
if kwargs.get('once', False):
|
if kwargs.get('once', False):
|
||||||
# if you don't want once to wait you can send it to the
|
# if you don't want once to wait you can send it to the
|
||||||
|
@ -1288,9 +1288,9 @@ class TestServer(unittest.TestCase):
|
|||||||
# setup pipe
|
# setup pipe
|
||||||
rfd, wfd = os.pipe()
|
rfd, wfd = os.pipe()
|
||||||
# subprocess connection to read stdout
|
# subprocess connection to read stdout
|
||||||
self.stdout = os.fdopen(rfd)
|
self.stdout = os.fdopen(rfd, 'rb')
|
||||||
# real process connection to write stdout
|
# real process connection to write stdout
|
||||||
self._stdout = os.fdopen(wfd, 'w')
|
self._stdout = os.fdopen(wfd, 'wb')
|
||||||
self.delay = delay
|
self.delay = delay
|
||||||
self.finished = False
|
self.finished = False
|
||||||
self.returncode = None
|
self.returncode = None
|
||||||
@ -1317,9 +1317,9 @@ class TestServer(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def fail(self):
|
def fail(self):
|
||||||
print('mock process started', file=self._stdout)
|
self._stdout.write(b'mock process started\n')
|
||||||
sleep(self.delay) # perform setup processing
|
sleep(self.delay) # perform setup processing
|
||||||
print('mock process failed to start', file=self._stdout)
|
self._stdout.write(b'mock process failed to start\n')
|
||||||
self.close_stdout()
|
self.close_stdout()
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
@ -1327,12 +1327,12 @@ class TestServer(unittest.TestCase):
|
|||||||
return self.returncode or None
|
return self.returncode or None
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print('mock process started', file=self._stdout)
|
self._stdout.write(b'mock process started\n')
|
||||||
sleep(self.delay) # perform setup processing
|
sleep(self.delay) # perform setup processing
|
||||||
print('setup complete!', file=self._stdout)
|
self._stdout.write(b'setup complete!\n')
|
||||||
self.close_stdout()
|
self.close_stdout()
|
||||||
sleep(self.delay) # do some more processing
|
sleep(self.delay) # do some more processing
|
||||||
print('mock process finished', file=self._stdout)
|
self._stdout.write(b'mock process finished\n')
|
||||||
self.finished = True
|
self.finished = True
|
||||||
|
|
||||||
class MockTime(object):
|
class MockTime(object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user