From 7d21cc582282d4796e2717b46bf38b226b68aa64 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 29 May 2018 16:50:23 -0400 Subject: [PATCH] pylint and more tests --- lbrynet/dht/datastore.py | 4 ++- lbrynet/dht/distance.py | 2 +- .../tests/functional/dht/test_contact_rpc.py | 32 +------------------ lbrynet/tests/unit/dht/test_routingtable.py | 3 +- 4 files changed, 7 insertions(+), 34 deletions(-) diff --git a/lbrynet/dht/datastore.py b/lbrynet/dht/datastore.py index 012122335..72969a772 100644 --- a/lbrynet/dht/datastore.py +++ b/lbrynet/dht/datastore.py @@ -51,7 +51,9 @@ class DictDataStore(UserDict.DictMixin): def addPeerToBlob(self, contact, key, compact_address, lastPublished, originallyPublished, originalPublisherID): if key in self._dict: if compact_address not in map(lambda store_tuple: store_tuple[1], self._dict[key]): - self._dict[key].append((contact, compact_address, lastPublished, originallyPublished, originalPublisherID)) + self._dict[key].append( + (contact, compact_address, lastPublished, originallyPublished, originalPublisherID) + ) else: self._dict[key] = [(contact, compact_address, lastPublished, originallyPublished, originalPublisherID)] diff --git a/lbrynet/dht/distance.py b/lbrynet/dht/distance.py index 8945f8b30..2c93ae9c2 100644 --- a/lbrynet/dht/distance.py +++ b/lbrynet/dht/distance.py @@ -10,7 +10,7 @@ class Distance(object): def __init__(self, key): if len(key) != constants.key_bits / 8: - raise ValueError("invalid key length: %i", len(key)) + raise ValueError("invalid key length: %i" % len(key)) self.key = key self.val_key_one = long(key.encode('hex'), 16) diff --git a/lbrynet/tests/functional/dht/test_contact_rpc.py b/lbrynet/tests/functional/dht/test_contact_rpc.py index a7dd43199..7f3141ecf 100644 --- a/lbrynet/tests/functional/dht/test_contact_rpc.py +++ b/lbrynet/tests/functional/dht/test_contact_rpc.py @@ -131,38 +131,8 @@ class KademliaProtocolTest(unittest.TestCase): raised locally """ remote_node = Node(node_id='2' * 48, udpPort=self.udpPort, externalIP="127.0.0.2", listenUDP=listenUDP, resolve=resolve, clock=self._reactor, callLater=self._reactor.callLater) - remote_node.start_listening() remote_contact = remote_node.contact_manager.make_contact('2' * 48, '127.0.0.2', 9182, self.node._protocol) - self.node.addContact(remote_contact) - - self.error = None - - def handleError(f): - try: - f.raiseException() - except AttributeError, e: - # This is the expected outcome since the remote node did not publish the method - self.error = None - except Exception, e: - self.error = 'The remote method failed, but the wrong exception was raised; ' \ - 'expected AttributeError, got %s' % type(e) - - def handleResult(result): - self.error = 'The remote method executed successfully, returning: "%s"; ' \ - 'this RPC should not have been allowed.' % result - - self.node.start_listening() - self._reactor.pump([1 for _ in range(10)]) - # Simulate the RPC - df = remote_contact.not_a_rpc_function() - df.addCallback(handleResult) - df.addErrback(handleError) - self._reactor.pump([1 for _ in range(10)]) - self.failIf(self.error, self.error) - # The list of sent RPC messages should be empty at this stage - self.failUnlessEqual(len(self.node._protocol._sentMessages), 0, - 'The protocol is still waiting for a RPC result, ' - 'but the transaction is already done!') + self.assertRaises(AttributeError, getattr, remote_contact, "not_a_rpc_function") def testRPCRequestArgs(self): """ Tests if an RPC requiring arguments is executed correctly """ diff --git a/lbrynet/tests/unit/dht/test_routingtable.py b/lbrynet/tests/unit/dht/test_routingtable.py index ebe1698f9..c9a6a0a5c 100644 --- a/lbrynet/tests/unit/dht/test_routingtable.py +++ b/lbrynet/tests/unit/dht/test_routingtable.py @@ -159,7 +159,8 @@ class TreeRoutingTableTest(unittest.TestCase): self.failUnlessEqual(len(self.routingTable._buckets[1]._contacts), 2) # try adding a contact who is further from us than the k'th known contact - nodeID = '020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'.decode('hex') + nodeID = '020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' + nodeID = nodeID.decode('hex') contact = self.contact_manager.make_contact(nodeID, '127.0.0.1', 9182, self.protocol) self.assertFalse(self.routingTable._shouldSplit(self.routingTable._kbucketIndex(contact.id), contact.id)) yield self.routingTable.addContact(contact)