test_netstring.py: move netstring tests to a separate file
authorBrian Warner <warner@allmydata.com>
Fri, 26 Sep 2008 16:55:26 +0000 (09:55 -0700)
committerBrian Warner <warner@allmydata.com>
Fri, 26 Sep 2008 16:55:26 +0000 (09:55 -0700)
src/allmydata/test/test_dirnode.py
src/allmydata/test/test_netstring.py [new file with mode: 0644]

index 621665a40cb383ddc9b352afaaedb64fe7a17245..90f26bfdb43d4b8fe4112384b22284f36b4cef49 100644 (file)
@@ -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 (file)
index 0000000..3923a0e
--- /dev/null
@@ -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"))
+
+