From f905d8076011c3e3e50b7b9416e05d5d18f3a43b Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Tue, 5 Feb 2019 11:03:35 -0500 Subject: [PATCH] switch to pytest_twisted --- integration/conftest.py | 53 ++++++++++++------------ integration/test_magic_folder.py | 6 +-- integration/test_servers_of_happiness.py | 4 +- integration/test_tor.py | 6 +-- integration/util.py | 4 +- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/integration/conftest.py b/integration/conftest.py index 34b1b4418..02a6ecba3 100644 --- a/integration/conftest.py +++ b/integration/conftest.py @@ -16,6 +16,7 @@ from twisted.internet.error import ( ) import pytest +import pytest_twisted from util import _CollectOutputProtocol from util import _MagicTextProtocol @@ -91,7 +92,7 @@ def flog_gatherer(reactor, temp_dir, flog_binary, request): gather_dir, ) ) - pytest.blockon(out_protocol.done) + pytest_twisted.blockon(out_protocol.done) twistd_protocol = _MagicTextProtocol("Gatherer waiting at") twistd_process = reactor.spawnProcess( @@ -103,12 +104,12 @@ def flog_gatherer(reactor, temp_dir, flog_binary, request): ), path=gather_dir, ) - pytest.blockon(twistd_protocol.magic_seen) + pytest_twisted.blockon(twistd_protocol.magic_seen) def cleanup(): try: twistd_process.signalProcess('TERM') - pytest.blockon(twistd_protocol.exited) + pytest_twisted.blockon(twistd_protocol.exited) except ProcessExitedAlready: pass @@ -125,7 +126,7 @@ def flog_gatherer(reactor, temp_dir, flog_binary, request): 'flogtool', 'dump', join(temp_dir, 'flog_gather', flogs[0]) ), ) - pytest.blockon(flog_protocol.done) + pytest_twisted.blockon(flog_protocol.done) request.addfinalizer(cleanup) @@ -160,7 +161,7 @@ log_gatherer.furl = {log_furl} intro_dir, ), ) - pytest.blockon(done_proto.done) + pytest_twisted.blockon(done_proto.done) # over-write the config file with our stuff with open(join(intro_dir, 'tahoe.cfg'), 'w') as f: @@ -183,12 +184,12 @@ log_gatherer.furl = {log_furl} def cleanup(): try: process.signalProcess('TERM') - pytest.blockon(protocol.exited) + pytest_twisted.blockon(protocol.exited) except ProcessExitedAlready: pass request.addfinalizer(cleanup) - pytest.blockon(protocol.magic_seen) + pytest_twisted.blockon(protocol.magic_seen) return process @@ -228,7 +229,7 @@ log_gatherer.furl = {log_furl} intro_dir, ), ) - pytest.blockon(done_proto.done) + pytest_twisted.blockon(done_proto.done) # over-write the config file with our stuff with open(join(intro_dir, 'tahoe.cfg'), 'w') as f: @@ -251,12 +252,12 @@ log_gatherer.furl = {log_furl} def cleanup(): try: process.signalProcess('TERM') - pytest.blockon(protocol.exited) + pytest_twisted.blockon(protocol.exited) except ProcessExitedAlready: pass request.addfinalizer(cleanup) - pytest.blockon(protocol.magic_seen) + pytest_twisted.blockon(protocol.magic_seen) return process @@ -278,14 +279,14 @@ def storage_nodes(reactor, temp_dir, introducer, introducer_furl, flog_gatherer, name = 'node{}'.format(x) # tub_port = 9900 + x nodes.append( - pytest.blockon( + pytest_twisted.blockon( _create_node( reactor, request, temp_dir, introducer_furl, flog_gatherer, name, web_port=None, storage=True, ) ) ) - #nodes = pytest.blockon(DeferredList(nodes)) + #nodes = pytest_twisted.blockon(DeferredList(nodes)) return nodes @@ -296,7 +297,7 @@ def alice(reactor, temp_dir, introducer_furl, flog_gatherer, storage_nodes, requ except OSError: pass - process = pytest.blockon( + process = pytest_twisted.blockon( _create_node( reactor, request, temp_dir, introducer_furl, flog_gatherer, "alice", web_port="tcp:9980:interface=localhost", @@ -313,7 +314,7 @@ def bob(reactor, temp_dir, introducer_furl, flog_gatherer, storage_nodes, reques except OSError: pass - process = pytest.blockon( + process = pytest_twisted.blockon( _create_node( reactor, request, temp_dir, introducer_furl, flog_gatherer, "bob", web_port="tcp:9981:interface=localhost", @@ -343,7 +344,7 @@ def alice_invite(reactor, alice, temp_dir, request): join(temp_dir, 'magic-alice'), ] ) - pytest.blockon(proto.done) + pytest_twisted.blockon(proto.done) proto = _CollectOutputProtocol() reactor.spawnProcess( @@ -355,7 +356,7 @@ def alice_invite(reactor, alice, temp_dir, request): '--basedir', node_dir, 'magik:', 'bob', ] ) - pytest.blockon(proto.done) + pytest_twisted.blockon(proto.done) invite = proto.output.getvalue() print("invite from alice", invite) @@ -363,11 +364,11 @@ def alice_invite(reactor, alice, temp_dir, request): # crappy for the tests -- can we fix it in magic-folder?) try: alice.signalProcess('TERM') - pytest.blockon(alice.exited) + pytest_twisted.blockon(alice.exited) except ProcessExitedAlready: pass magic_text = 'Completed initial Magic Folder scan successfully' - pytest.blockon(_run_node(reactor, node_dir, request, magic_text)) + pytest_twisted.blockon(_run_node(reactor, node_dir, request, magic_text)) return invite @@ -388,19 +389,19 @@ def magic_folder(reactor, alice_invite, alice, bob, temp_dir, request): join(temp_dir, 'magic-bob'), ] ) - pytest.blockon(proto.done) + pytest_twisted.blockon(proto.done) # before magic-folder works, we have to stop and restart (this is # crappy for the tests -- can we fix it in magic-folder?) try: print("Sending TERM to Bob") bob.signalProcess('TERM') - pytest.blockon(bob.exited) + pytest_twisted.blockon(bob.exited) except ProcessExitedAlready: pass magic_text = 'Completed initial Magic Folder scan successfully' - pytest.blockon(_run_node(reactor, bob_dir, request, magic_text)) + pytest_twisted.blockon(_run_node(reactor, bob_dir, request, magic_text)) return (join(temp_dir, 'magic-alice'), join(temp_dir, 'magic-bob')) @@ -429,7 +430,7 @@ def chutney(reactor, temp_dir): chutney_dir, ) ) - pytest.blockon(proto.done) + pytest_twisted.blockon(proto.done) return chutney_dir @@ -454,7 +455,7 @@ def tor_network(reactor, temp_dir, chutney, request): path=join(chutney_dir), env={"PYTHONPATH": join(chutney_dir, "lib")}, ) - pytest.blockon(proto.done) + pytest_twisted.blockon(proto.done) proto = _DumpOutputProtocol(None) reactor.spawnProcess( @@ -467,7 +468,7 @@ def tor_network(reactor, temp_dir, chutney, request): path=join(chutney_dir), env={"PYTHONPATH": join(chutney_dir, "lib")}, ) - pytest.blockon(proto.done) + pytest_twisted.blockon(proto.done) # print some useful stuff proto = _CollectOutputProtocol() @@ -482,7 +483,7 @@ def tor_network(reactor, temp_dir, chutney, request): env={"PYTHONPATH": join(chutney_dir, "lib")}, ) try: - pytest.blockon(proto.done) + pytest_twisted.blockon(proto.done) except ProcessTerminated: print("Chutney.TorNet status failed (continuing):") print(proto.output.getvalue()) @@ -500,7 +501,7 @@ def tor_network(reactor, temp_dir, chutney, request): path=join(chutney_dir), env={"PYTHONPATH": join(chutney_dir, "lib")}, ) - pytest.blockon(proto.done) + pytest_twisted.blockon(proto.done) request.addfinalizer(cleanup) return chut diff --git a/integration/test_magic_folder.py b/integration/test_magic_folder.py index f03cf510a..dafd294e6 100644 --- a/integration/test_magic_folder.py +++ b/integration/test_magic_folder.py @@ -1,12 +1,12 @@ import sys import time import shutil -from os import mkdir, unlink, listdir, utime +from os import mkdir, unlink, utime from os.path import join, exists, getmtime import util -import pytest +import pytest_twisted # tests converted from check_magicfolder_smoke.py @@ -280,7 +280,7 @@ def _bob_conflicts_alice_await_conflicts(name, alice_dir, bob_dir): assert open(alice_conflict, 'r').read() == "this is bob's {}\n".format(name) -@pytest.inlineCallbacks +@pytest_twisted.inlineCallbacks def test_edmond_uploads_then_restarts(reactor, request, temp_dir, introducer_furl, flog_gatherer, storage_nodes): """ ticket 2880: if a magic-folder client uploads something, then diff --git a/integration/test_servers_of_happiness.py b/integration/test_servers_of_happiness.py index 1688b056a..1f84094e2 100644 --- a/integration/test_servers_of_happiness.py +++ b/integration/test_servers_of_happiness.py @@ -6,10 +6,10 @@ from twisted.internet.error import ProcessTerminated import util -import pytest +import pytest_twisted -@pytest.inlineCallbacks +@pytest_twisted.inlineCallbacks def test_upload_immutable(reactor, temp_dir, introducer_furl, flog_gatherer, storage_nodes, request): yield util._create_node( diff --git a/integration/test_tor.py b/integration/test_tor.py index 6eb58d1bb..bc39d8ab0 100644 --- a/integration/test_tor.py +++ b/integration/test_tor.py @@ -10,13 +10,13 @@ from StringIO import StringIO from twisted.internet.protocol import ProcessProtocol from twisted.internet.error import ProcessExitedAlready, ProcessDone from twisted.internet.defer import inlineCallbacks, Deferred -import pytest +import pytest_twisted import util # see "conftest.py" for the fixtures (e.g. "magic_folder") -@pytest.inlineCallbacks +@pytest_twisted.inlineCallbacks def test_onion_service_storage(reactor, request, temp_dir, flog_gatherer, tor_network, tor_introducer_furl): yield _create_anonymous_node(reactor, 'carol', 8008, request, temp_dir, flog_gatherer, tor_network, tor_introducer_furl) yield _create_anonymous_node(reactor, 'dave', 8009, request, temp_dir, flog_gatherer, tor_network, tor_introducer_furl) @@ -62,7 +62,7 @@ def test_onion_service_storage(reactor, request, temp_dir, flog_gatherer, tor_ne assert dave_got == open(gold_path, 'r').read().strip() -@pytest.inlineCallbacks +@pytest_twisted.inlineCallbacks def _create_anonymous_node(reactor, name, control_port, request, temp_dir, flog_gatherer, tor_network, introducer_furl): node_dir = join(temp_dir, name) web_port = "tcp:{}:interface=localhost".format(control_port + 2000) diff --git a/integration/util.py b/integration/util.py index 650b0a18e..b542bf9f3 100644 --- a/integration/util.py +++ b/integration/util.py @@ -14,7 +14,7 @@ from allmydata.util.configutil import ( write_config, ) -import pytest +import pytest_twisted class _ProcessExitedProtocol(ProcessProtocol): @@ -127,7 +127,7 @@ def _run_node(reactor, node_dir, request, magic_text): def cleanup(): try: process.signalProcess('TERM') - pytest.blockon(protocol.exited) + pytest_twisted.blockon(protocol.exited) except ProcessExitedAlready: pass request.addfinalizer(cleanup)