Tests pass on Python 3.

This commit is contained in:
Itamar Turner-Trauring 2021-05-11 11:56:21 -04:00
parent 070691caa2
commit 4043b2fe1f
2 changed files with 11 additions and 7 deletions

View File

@ -6,7 +6,7 @@ from os.path import join
import pytest import pytest
import pytest_twisted import pytest_twisted
import util from . import util
from twisted.python.filepath import ( from twisted.python.filepath import (
FilePath, FilePath,
@ -55,7 +55,7 @@ def test_onion_service_storage(reactor, request, temp_dir, flog_gatherer, tor_ne
cap = proto.output.getvalue().strip().split()[-1] cap = proto.output.getvalue().strip().split()[-1]
print("TEH CAP!", cap) print("TEH CAP!", cap)
proto = util._CollectOutputProtocol() proto = util._CollectOutputProtocol(capture_stderr=False)
reactor.spawnProcess( reactor.spawnProcess(
proto, proto,
sys.executable, sys.executable,
@ -68,7 +68,7 @@ def test_onion_service_storage(reactor, request, temp_dir, flog_gatherer, tor_ne
yield proto.done yield proto.done
dave_got = proto.output.getvalue().strip() dave_got = proto.output.getvalue().strip()
assert dave_got == open(gold_path, 'r').read().strip() assert dave_got == open(gold_path, 'rb').read().strip()
@pytest_twisted.inlineCallbacks @pytest_twisted.inlineCallbacks
@ -100,7 +100,7 @@ def _create_anonymous_node(reactor, name, control_port, request, temp_dir, flog_
# Which services should this client connect to? # Which services should this client connect to?
write_introducer(node_dir, "default", introducer_furl) write_introducer(node_dir, "default", introducer_furl)
with node_dir.child('tahoe.cfg').open('w') as f: with node_dir.child('tahoe.cfg').open('w') as f:
f.write(''' node_config = '''
[node] [node]
nickname = %(name)s nickname = %(name)s
web.port = %(web_port)s web.port = %(web_port)s
@ -125,7 +125,9 @@ shares.total = 2
'log_furl': flog_gatherer, 'log_furl': flog_gatherer,
'control_port': control_port, 'control_port': control_port,
'local_port': control_port + 1000, 'local_port': control_port + 1000,
}) }
node_config = node_config.encode("utf-8")
f.write(node_config)
print("running") print("running")
yield util._run_node(reactor, node_dir.path, request, None) yield util._run_node(reactor, node_dir.path, request, None)

View File

@ -57,9 +57,10 @@ class _CollectOutputProtocol(ProcessProtocol):
self.output, and callback's on done with all of it after the self.output, and callback's on done with all of it after the
process exits (for any reason). process exits (for any reason).
""" """
def __init__(self): def __init__(self, capture_stderr=True):
self.done = Deferred() self.done = Deferred()
self.output = BytesIO() self.output = BytesIO()
self.capture_stderr = capture_stderr
def processEnded(self, reason): def processEnded(self, reason):
if not self.done.called: if not self.done.called:
@ -74,6 +75,7 @@ class _CollectOutputProtocol(ProcessProtocol):
def errReceived(self, data): def errReceived(self, data):
print("ERR: {!r}".format(data)) print("ERR: {!r}".format(data))
if self.capture_err:
self.output.write(data) self.output.write(data)