From: Brian Warner Date: Fri, 26 Sep 2008 16:55:26 +0000 (-0700) Subject: test_netstring.py: move netstring tests to a separate file X-Git-Url: https://git.rkrishnan.org/somewhere?a=commitdiff_plain;h=27a30b90d787b708a3e1f7d92d097b55cb431e07;p=tahoe-lafs%2Ftahoe-lafs.git test_netstring.py: move netstring tests to a separate file --- diff --git a/src/allmydata/test/test_dirnode.py b/src/allmydata/test/test_dirnode.py index 621665a4..90f26bfd 100644 --- a/src/allmydata/test/test_dirnode.py +++ b/src/allmydata/test/test_dirnode.py @@ -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")) - diff --git a/src/allmydata/test/test_netstring.py b/src/allmydata/test/test_netstring.py new file mode 100644 index 00000000..3923a0e1 --- /dev/null +++ b/src/allmydata/test/test_netstring.py @@ -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")) + +