mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 03:06:33 +00:00
test_netstring.py: move netstring tests to a separate file
This commit is contained in:
parent
e8cf581e3f
commit
27a30b90d7
@ -693,39 +693,3 @@ class DeepStats(unittest.TestCase):
|
||||
(3162277660169L, 10000000000000L, 1),
|
||||
])
|
||||
|
||||
|
||||
netstring = hashutil.netstring
|
||||
split_netstring = dirnode.split_netstring
|
||||
|
||||
class Netstring(unittest.TestCase):
|
||||
def test_split(self):
|
||||
a = netstring("hello") + netstring("world")
|
||||
self.failUnlessEqual(split_netstring(a, 2), ("hello", "world"))
|
||||
self.failUnlessEqual(split_netstring(a, 2, False), ("hello", "world"))
|
||||
self.failUnlessEqual(split_netstring(a, 2, True),
|
||||
("hello", "world", ""))
|
||||
self.failUnlessRaises(ValueError, split_netstring, a, 3)
|
||||
self.failUnlessRaises(ValueError, split_netstring, a+" extra", 2)
|
||||
self.failUnlessRaises(ValueError, split_netstring, a+" extra", 2, False)
|
||||
|
||||
def test_extra(self):
|
||||
a = netstring("hello")
|
||||
self.failUnlessEqual(split_netstring(a, 1, True), ("hello", ""))
|
||||
b = netstring("hello") + "extra stuff"
|
||||
self.failUnlessEqual(split_netstring(b, 1, True),
|
||||
("hello", "extra stuff"))
|
||||
|
||||
def test_nested(self):
|
||||
a = netstring("hello") + netstring("world") + "extra stuff"
|
||||
b = netstring("a") + netstring("is") + netstring(a) + netstring(".")
|
||||
top = split_netstring(b, 4)
|
||||
self.failUnlessEqual(len(top), 4)
|
||||
self.failUnlessEqual(top[0], "a")
|
||||
self.failUnlessEqual(top[1], "is")
|
||||
self.failUnlessEqual(top[2], a)
|
||||
self.failUnlessEqual(top[3], ".")
|
||||
self.failUnlessRaises(ValueError, split_netstring, a, 2)
|
||||
self.failUnlessRaises(ValueError, split_netstring, a, 2, False)
|
||||
bottom = split_netstring(a, 2, True)
|
||||
self.failUnlessEqual(bottom, ("hello", "world", "extra stuff"))
|
||||
|
||||
|
37
src/allmydata/test/test_netstring.py
Normal file
37
src/allmydata/test/test_netstring.py
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
from twisted.trial import unittest
|
||||
from allmydata.util.netstring import netstring, split_netstring
|
||||
|
||||
class Netstring(unittest.TestCase):
|
||||
def test_split(self):
|
||||
a = netstring("hello") + netstring("world")
|
||||
self.failUnlessEqual(split_netstring(a, 2), ("hello", "world"))
|
||||
self.failUnlessEqual(split_netstring(a, 2, False), ("hello", "world"))
|
||||
self.failUnlessEqual(split_netstring(a, 2, True),
|
||||
("hello", "world", ""))
|
||||
self.failUnlessRaises(ValueError, split_netstring, a, 3)
|
||||
self.failUnlessRaises(ValueError, split_netstring, a+" extra", 2)
|
||||
self.failUnlessRaises(ValueError, split_netstring, a+" extra", 2, False)
|
||||
|
||||
def test_extra(self):
|
||||
a = netstring("hello")
|
||||
self.failUnlessEqual(split_netstring(a, 1, True), ("hello", ""))
|
||||
b = netstring("hello") + "extra stuff"
|
||||
self.failUnlessEqual(split_netstring(b, 1, True),
|
||||
("hello", "extra stuff"))
|
||||
|
||||
def test_nested(self):
|
||||
a = netstring("hello") + netstring("world") + "extra stuff"
|
||||
b = netstring("a") + netstring("is") + netstring(a) + netstring(".")
|
||||
top = split_netstring(b, 4)
|
||||
self.failUnlessEqual(len(top), 4)
|
||||
self.failUnlessEqual(top[0], "a")
|
||||
self.failUnlessEqual(top[1], "is")
|
||||
self.failUnlessEqual(top[2], a)
|
||||
self.failUnlessEqual(top[3], ".")
|
||||
self.failUnlessRaises(ValueError, split_netstring, a, 2)
|
||||
self.failUnlessRaises(ValueError, split_netstring, a, 2, False)
|
||||
bottom = split_netstring(a, 2, True)
|
||||
self.failUnlessEqual(bottom, ("hello", "world", "extra stuff"))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user