more flake8 fixes

This commit is contained in:
Brian Warner 2018-06-30 16:23:39 -07:00
parent ea35e570a2
commit bf0c93eddc
13 changed files with 155 additions and 96 deletions

View File

@ -80,28 +80,36 @@ class _Framer(object):
set_trace = getattr(m, "_setTrace", lambda self, f: None) # pragma: no cover
@m.state()
def want_relay(self): pass # pragma: no cover
def want_relay(self):
pass # pragma: no cover
@m.state(initial=True)
def want_prologue(self): pass # pragma: no cover
def want_prologue(self):
pass # pragma: no cover
@m.state()
def want_frame(self): pass # pragma: no cover
def want_frame(self):
pass # pragma: no cover
@m.input()
def use_relay(self, relay_handshake): pass
def use_relay(self, relay_handshake):
pass
@m.input()
def connectionMade(self): pass
def connectionMade(self):
pass
@m.input()
def parse(self): pass
def parse(self):
pass
@m.input()
def got_relay_ok(self): pass
def got_relay_ok(self):
pass
@m.input()
def got_prologue(self): pass
def got_prologue(self):
pass
@m.output()
def store_relay_handshake(self, relay_handshake):
@ -312,13 +320,16 @@ class _Record(object):
# states: want_prologue, want_handshake, want_record
@n.state(initial=True)
def want_prologue(self): pass # pragma: no cover
def want_prologue(self):
pass # pragma: no cover
@n.state()
def want_handshake(self): pass # pragma: no cover
def want_handshake(self):
pass # pragma: no cover
@n.state()
def want_message(self): pass # pragma: no cover
def want_message(self):
pass # pragma: no cover
@n.input()
def got_prologue(self):
@ -417,13 +428,16 @@ class DilatedConnectionProtocol(Protocol, object):
self._can_send_records = False
@m.state(initial=True)
def unselected(self): pass # pragma: no cover
def unselected(self):
pass # pragma: no cover
@m.state()
def selecting(self): pass # pragma: no cover
def selecting(self):
pass # pragma: no cover
@m.state()
def selected(self): pass # pragma: no cover
def selected(self):
pass # pragma: no cover
@m.input()
def got_kcm(self):

View File

@ -4,34 +4,53 @@ class ManagerFollower(_ManagerBase):
set_trace = getattr(m, "_setTrace", lambda self, f: None)
@m.state(initial=True)
def IDLE(self): pass # pragma: no cover
def IDLE(self):
pass # pragma: no cover
@m.state()
def WANTING(self): pass # pragma: no cover
def WANTING(self):
pass # pragma: no cover
@m.state()
def CONNECTING(self): pass # pragma: no cover
def CONNECTING(self):
pass # pragma: no cover
@m.state()
def CONNECTED(self): pass # pragma: no cover
def CONNECTED(self):
pass # pragma: no cover
@m.state(terminal=True)
def STOPPED(self): pass # pragma: no cover
def STOPPED(self):
pass # pragma: no cover
@m.input()
def start(self): pass # pragma: no cover
@m.input()
def rx_PLEASE(self): pass # pragma: no cover
@m.input()
def rx_DILATE(self): pass # pragma: no cover
@m.input()
def rx_HINTS(self, hint_message): pass # pragma: no cover
def start(self):
pass # pragma: no cover
@m.input()
def connection_made(self): pass # pragma: no cover
def rx_PLEASE(self):
pass # pragma: no cover
@m.input()
def connection_lost(self): pass # pragma: no cover
def rx_DILATE(self):
pass # pragma: no cover
@m.input()
def rx_HINTS(self, hint_message):
pass # pragma: no cover
@m.input()
def connection_made(self):
pass # pragma: no cover
@m.input()
def connection_lost(self):
pass # pragma: no cover
# follower doesn't react to connection_lost, but waits for a new LETS_DILATE
@m.input()
def stop(self): pass # pragma: no cover
def stop(self):
pass # pragma: no cover
# these Outputs behave differently for the Leader vs the Follower
@m.output()
@ -51,18 +70,23 @@ class ManagerFollower(_ManagerBase):
hint_objs = filter(lambda h: h, # ignore None, unrecognizable
[parse_hint(hs) for hs in hint_message["hints"]])
self._connector.got_hints(hint_objs)
@m.output()
def stop_connecting(self):
self._connector.stop()
@m.output()
def use_connection(self, c):
self._use_connection(c)
@m.output()
def stop_using_connection(self):
self._stop_using_connection()
@m.output()
def signal_error(self):
pass # TODO
@m.output()
def signal_error_hints(self, hint_message):
pass # TODO

View File

@ -3,16 +3,19 @@ import mock
from zope.interface import alsoProvides
from ..._interfaces import IDilationManager, IWormhole
def mock_manager():
m = mock.Mock()
alsoProvides(m, IDilationManager)
return m
def mock_wormhole():
m = mock.Mock()
alsoProvides(m, IWormhole)
return m
def clear_mock_calls(*args):
for a in args:
a.mock_calls[:] = []

View File

@ -11,6 +11,7 @@ from ..._dilation.connection import (DilatedConnectionProtocol, encode_record,
KCM, Open, Ack)
from .common import clear_mock_calls
def make_con(role, use_relay=False):
clock = Clock()
eq = EventualQueue(clock)
@ -26,6 +27,7 @@ def make_con(role, use_relay=False):
alsoProvides(t, ITransport)
return c, n, connector, t, eq
class Connection(unittest.TestCase):
def test_bad_prologue(self):
c, n, connector, t, eq = make_con(LEADER)
@ -163,7 +165,6 @@ class Connection(unittest.TestCase):
def test_no_relay_follower(self):
return self._test_no_relay(FOLLOWER)
def test_relay(self):
c, n, connector, t, eq = make_con(LEADER, use_relay=True)

View File

@ -2,6 +2,7 @@ from __future__ import print_function, unicode_literals
from twisted.trial import unittest
from ..._dilation.encode import to_be4, from_be4
class Encoding(unittest.TestCase):
def test_be4(self):

View File

@ -11,6 +11,7 @@ from ..._dilation.subchannel import (ControlEndpoint,
SingleUseEndpointError)
from .common import mock_manager
class Endpoints(unittest.TestCase):
def test_control(self):
scid0 = b"scid0"

View File

@ -5,12 +5,14 @@ from twisted.trial import unittest
from twisted.internet.interfaces import ITransport
from ..._dilation.connection import _Framer, Frame, Prologue, Disconnect
def make_framer():
t = mock.Mock()
alsoProvides(t, ITransport)
f = _Framer(t, b"outbound_prologue\n", b"inbound_prologue\n")
return f, t
class Framer(unittest.TestCase):
def test_bad_prologue_length(self):
f, t = make_framer()

View File

@ -8,6 +8,7 @@ from ..._dilation.inbound import (Inbound, DuplicateOpenError,
DataForMissingSubchannelError,
CloseForMissingSubchannelError)
def make_inbound():
m = mock.Mock()
alsoProvides(m, IDilationManager)
@ -15,6 +16,7 @@ def make_inbound():
i = Inbound(m, host_addr)
return i, m, host_addr
class InboundTest(unittest.TestCase):
def test_seqnum(self):
i, m, host_addr = make_inbound()

View File

@ -13,12 +13,14 @@ from ..._dilation.manager import (Dilator,
from ..._dilation.subchannel import _WormholeAddress
from .common import clear_mock_calls
def make_dilator():
reactor = object()
clock = Clock()
eq = EventualQueue(clock)
term = mock.Mock(side_effect=lambda: True) # one write per Eventual tick
term_factory = lambda: term
def term_factory(): return term
coop = Cooperator(terminationPredicateFactory=term_factory,
scheduler=eq.eventually)
send = mock.Mock()
@ -27,6 +29,7 @@ def make_dilator():
dil.wire(send)
return dil, send, reactor, eq, clock, coop
class TestDilator(unittest.TestCase):
def test_leader(self):
dil, send, reactor, eq, clock, coop = make_dilator()
@ -153,7 +156,6 @@ class TestDilator(unittest.TestCase):
f = self.failureResultOf(d1)
f.check(OldPeerCannotDilateError)
def test_disjoint_versions(self):
dil, send, reactor, eq, clock, coop = make_dilator()
d1 = dil.dilate()
@ -164,7 +166,6 @@ class TestDilator(unittest.TestCase):
f = self.failureResultOf(d1)
f.check(OldPeerCannotDilateError)
def test_early_dilate_messages(self):
dil, send, reactor, eq, clock, coop = make_dilator()
dil._transit_key = b"key"
@ -188,8 +189,6 @@ class TestDilator(unittest.TestCase):
mock.call.rx_HINTS(hintmsg),
mock.call.when_first_connected()])
def test_transit_relay(self):
dil, send, reactor, eq, clock, coop = make_dilator()
dil._transit_key = b"key"

View File

@ -16,17 +16,20 @@ Pauser = namedtuple("Pauser", ["seqnum"])
NonPauser = namedtuple("NonPauser", ["seqnum"])
Stopper = namedtuple("Stopper", ["sc"])
def make_outbound():
m = mock.Mock()
alsoProvides(m, IDilationManager)
clock = Clock()
eq = EventualQueue(clock)
term = mock.Mock(side_effect=lambda: True) # one write per Eventual tick
term_factory = lambda: term
def term_factory(): return term
coop = Cooperator(terminationPredicateFactory=term_factory,
scheduler=eq.eventually)
o = Outbound(m, coop)
c = mock.Mock() # Connection
def maybe_pause(r):
if isinstance(r, Pauser):
o.pauseProducing()
@ -37,6 +40,7 @@ def make_outbound():
o._test_term = term
return o, m, c
class OutboundTest(unittest.TestCase):
def test_build_record(self):
o, m, c = make_outbound()
@ -192,7 +196,8 @@ class OutboundTest(unittest.TestCase):
clear_mock_calls(c)
sc1, sc2, sc3 = object(), object(), object()
p1, p2, p3 = mock.Mock(name="p1"), mock.Mock(name="p2"), mock.Mock(name="p3")
p1, p2, p3 = mock.Mock(name="p1"), mock.Mock(
name="p2"), mock.Mock(name="p3")
# we aren't paused yet, since we haven't sent any data
o.subchannel_registerProducer(sc1, p1, True)
@ -310,7 +315,8 @@ class OutboundTest(unittest.TestCase):
# and another disconnects itself when called
p2.resumeProducing.side_effect = lambda: None
p3.resumeProducing.side_effect = lambda: o.subchannel_unregisterProducer(sc3)
p3.resumeProducing.side_effect = lambda: o.subchannel_unregisterProducer(
sc3)
o.pauseProducing()
o.resumeProducing()
self.assertEqual(p2.mock_calls, [mock.call.pauseProducing(),
@ -560,12 +566,14 @@ def make_pushpull(pauses):
clock = Clock()
eq = EventualQueue(clock)
term = mock.Mock(side_effect=lambda: True) # one write per Eventual tick
term_factory = lambda: term
def term_factory(): return term
coop = Cooperator(terminationPredicateFactory=term_factory,
scheduler=eq.eventually)
pp = PullToPush(p, unregister, coop)
it = cycle(pauses)
def action(i):
if isinstance(i, Exception):
raise i
@ -574,11 +582,15 @@ def make_pushpull(pauses):
p.resumeProducing.side_effect = lambda: action(next(it))
return p, unregister, pp, eq
class PretendResumptionError(Exception):
pass
class PretendUnregisterError(Exception):
pass
class PushPull(unittest.TestCase):
# test our wrapper utility, which I copied from
# twisted.internet._producer_helpers since it isn't publically exposed
@ -637,9 +649,5 @@ class PushPull(unittest.TestCase):
self.assertEqual(unr.mock_calls, [mock.call()])
self.flushLoggedErrors(PretendResumptionError, PretendUnregisterError)
# TODO: consider making p1/p2/p3 all elements of a shared Mock, maybe I
# could capture the inter-call ordering that way

View File

@ -4,6 +4,7 @@ from twisted.trial import unittest
from ..._dilation.connection import (parse_record, encode_record,
KCM, Ping, Pong, Open, Data, Close, Ack)
class Parse(unittest.TestCase):
def test_parse(self):
self.assertEqual(parse_record(b"\x00"), KCM())

View File

@ -7,6 +7,7 @@ from ..._dilation.connection import (IFramer, Frame, Prologue,
_Record, Handshake,
Disconnect, Ping)
def make_record():
f = mock.Mock()
alsoProvides(f, IFramer)
@ -14,6 +15,7 @@ def make_record():
r = _Record(f, n)
return r, f, n
class Record(unittest.TestCase):
def test_good2(self):
f = mock.Mock()
@ -238,7 +240,6 @@ class Record(unittest.TestCase):
f.mock_calls[:] = []
n.mock_calls[:] = []
# 5: at this point we ought to be able to send a messge, the KCM
with mock.patch("wormhole._dilation.connection.encode_record",
side_effect=[b"r-kcm"]) as er:

View File

@ -8,6 +8,7 @@ from ..._dilation.subchannel import (Once, SubChannel,
AlreadyClosedError)
from .common import mock_manager
def make_sc(set_protocol=True):
scid = b"scid"
hostaddr = _WormholeAddress()
@ -19,6 +20,7 @@ def make_sc(set_protocol=True):
sc._set_protocol(p)
return sc, m, scid, hostaddr, peeraddr, p
class SubChannelAPI(unittest.TestCase):
def test_once(self):
o = Once(ValueError)