]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
refactor test_uri and add a test of the empty file
authorZooko O'Whielacronx <zooko@zooko.com>
Thu, 26 Jul 2007 17:48:30 +0000 (10:48 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Thu, 26 Jul 2007 17:48:30 +0000 (10:48 -0700)
src/allmydata/test/test_uri.py

index a05e8e5eff6183a377a9c8977df0582f3f50cab9..835d4f2ac0c4d0efe2f1d6e8346f34e76db6c0bc 100644 (file)
@@ -5,8 +5,7 @@ from allmydata.util import hashutil
 from allmydata.interfaces import IURI, IFileURI, IDirnodeURI
 
 class Literal(unittest.TestCase):
-    def test_pack(self):
-        data = "This is some small data"
+    def _help_test(self, data):
         u = uri.LiteralFileURI(data)
         self.failUnless(IURI.providedBy(u))
         self.failUnless(IFileURI.providedBy(u))
@@ -24,26 +23,18 @@ class Literal(unittest.TestCase):
         self.failUnlessEqual(u2.get_size(), len(data))
         self.failUnless(u.is_readonly())
         self.failIf(u.is_mutable())
+        
+    def test_empty(self):
+        data = "" # This data is some *very* small data!
+        return self._help_test(data)
+    
+    def test_pack(self):
+        data = "This is some small data"
+        return self._help_test(data)
 
     def test_nonascii(self):
         data = "This contains \x00 and URI:LIT: and \n, oh my."
-        u = uri.LiteralFileURI(data)
-        self.failUnless(IURI.providedBy(u))
-        self.failUnless(IFileURI.providedBy(u))
-        self.failIf(IDirnodeURI.providedBy(u))
-        self.failUnlessEqual(u.data, data)
-        self.failUnlessEqual(u.get_size(), len(data))
-        self.failUnless(u.is_readonly())
-        self.failIf(u.is_mutable())
-
-        u2 = uri.from_string(u.to_string())
-        self.failUnless(IURI.providedBy(u2))
-        self.failUnless(IFileURI.providedBy(u2))
-        self.failIf(IDirnodeURI.providedBy(u2))
-        self.failUnlessEqual(u2.data, data)
-        self.failUnlessEqual(u2.get_size(), len(data))
-        self.failUnless(u.is_readonly())
-        self.failIf(u.is_mutable())
+        return self._help_test(data)
 
 class CHKFile(unittest.TestCase):
     def test_pack(self):