appease flake8 somewhat

This commit is contained in:
Brian Warner 2018-12-21 21:54:17 -05:00
parent 40dadfeb71
commit 3b7c9831f6
2 changed files with 37 additions and 31 deletions

View File

@ -45,6 +45,7 @@ class UnexpectedKCM(Exception):
class UnknownMessageType(Exception):
pass
def make_side():
return bytes_to_hexstr(os.urandom(6))

View File

@ -35,6 +35,7 @@ def make_dilator():
dil.wire(send)
return dil, send, reactor, eq, clock, coop
class TestDilator(unittest.TestCase):
def test_manager_and_endpoints(self):
dil, send, reactor, eq, clock, coop = make_dilator()
@ -142,7 +143,7 @@ class TestDilator(unittest.TestCase):
d1 = dil.dilate()
self.assertNoResult(d1)
dil._transit_key = b"\x01"*32
dil._transit_key = b"\x01" * 32
dil.got_wormhole_versions({}) # missing "can-dilate"
eq.flush_sync()
f = self.failureResultOf(d1)
@ -201,9 +202,11 @@ class TestDilator(unittest.TestCase):
mock.call().start(),
mock.call().when_first_connected()])
LEADER = "ff3456abcdef"
FOLLOWER = "123456abcdef"
def make_manager(leader=True):
class Holder:
pass
@ -214,12 +217,13 @@ def make_manager(leader=True):
side = LEADER
else:
side = FOLLOWER
h.key = b"\x00"*32
h.key = b"\x00" * 32
h.relay = None
h.reactor = object()
h.clock = Clock()
h.eq = EventualQueue(h.clock)
term = mock.Mock(side_effect=lambda: True) # one write per Eventual tick
def term_factory():
return term
h.coop = Cooperator(terminationPredicateFactory=term_factory,
@ -236,11 +240,12 @@ def make_manager(leader=True):
m = Manager(h.send, side, h.key, h.relay, h.reactor, h.eq, h.coop)
return m, h
class TestManager(unittest.TestCase):
def test_make_side(self):
side = make_side()
self.assertEqual(type(side), type(u""))
self.assertEqual(len(side), 2*6)
self.assertEqual(len(side), 2 * 6)
def test_create(self):
m, h = make_manager()
@ -272,7 +277,7 @@ class TestManager(unittest.TestCase):
m.rx_PLEASE({"side": FOLLOWER})
self.assertEqual(h.send.mock_calls, [])
self.assertEqual(connector.mock_calls, [
mock.call(b"\x00"*32, None, m, h.reactor, h.eq,
mock.call(b"\x00" * 32, None, m, h.reactor, h.eq,
False, # no_listen
None, # tor
None, # timing
@ -292,7 +297,7 @@ class TestManager(unittest.TestCase):
clear_mock_calls(ph, c)
# and we send out any (listening) hints from our Connector
m.send_hints([1,2])
m.send_hints([1, 2])
self.assertEqual(h.send.mock_calls, [
mock.call.send("dilate-1",
dict_to_bytes({"type": "connection-hints",
@ -448,7 +453,7 @@ class TestManager(unittest.TestCase):
m.rx_RECONNECTING()
self.assertEqual(h.send.mock_calls, [])
self.assertEqual(connector2.mock_calls, [
mock.call(b"\x00"*32, None, m, h.reactor, h.eq,
mock.call(b"\x00" * 32, None, m, h.reactor, h.eq,
False, # no_listen
None, # tor
None, # timing
@ -486,7 +491,7 @@ class TestManager(unittest.TestCase):
m.rx_PLEASE({"side": LEADER})
self.assertEqual(h.send.mock_calls, [])
self.assertEqual(connector.mock_calls, [
mock.call(b"\x00"*32, None, m, h.reactor, h.eq,
mock.call(b"\x00" * 32, None, m, h.reactor, h.eq,
False, # no_listen
None, # tor
None, # timing
@ -524,7 +529,7 @@ class TestManager(unittest.TestCase):
dict_to_bytes({"type": "reconnecting"}))
])
self.assertEqual(connector2.mock_calls, [
mock.call(b"\x00"*32, None, m, h.reactor, h.eq,
mock.call(b"\x00" * 32, None, m, h.reactor, h.eq,
False, # no_listen
None, # tor
None, # timing
@ -541,7 +546,7 @@ class TestManager(unittest.TestCase):
m.rx_RECONNECT()
self.assertEqual(c2.mock_calls, [mock.call.stop()])
self.assertEqual(connector3.mock_calls, [
mock.call(b"\x00"*32, None, m, h.reactor, h.eq,
mock.call(b"\x00" * 32, None, m, h.reactor, h.eq,
False, # no_listen
None, # tor
None, # timing
@ -563,7 +568,7 @@ class TestManager(unittest.TestCase):
m.connector_connection_lost()
self.assertEqual(c3.mock_calls, [mock.call.disconnect()])
self.assertEqual(connector4.mock_calls, [
mock.call(b"\x00"*32, None, m, h.reactor, h.eq,
mock.call(b"\x00" * 32, None, m, h.reactor, h.eq,
False, # no_listen
None, # tor
None, # timing