pylint and more tests
This commit is contained in:
parent
cce3c8c7b5
commit
7d21cc5822
4 changed files with 7 additions and 34 deletions
|
@ -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)]
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 """
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue