add unit test for mishandling access(3)
[python-delta-tar] / testing / test_deltatar.py
index f16208d..9a0b7d6 100644 (file)
@@ -52,6 +52,9 @@ class DeltaTarTest(BaseTest):
 
     GIT_DIR = '.git'
 
+    FSTEST = None
+    FSAPI_SAVED = []
+
     def setUp(self):
         '''
         Create base test data
@@ -79,10 +82,16 @@ class DeltaTarTest(BaseTest):
             if not os.path.isdir(self.GIT_DIR):
                 raise Exception('No input directory found: ' + self.GIT_DIR)
 
+        if self.FSTEST is not None:
+            self.FSTEST ()
+
     def tearDown(self):
         '''
-        Remove temporal files created by unit tests and reset globals.
+        Remove temporary files created by unit tests and restore the API
+        functions in *os*.
         '''
+        for att, val in self.FSAPI_SAVED:
+            setattr (os, att, val)
         os.chdir(self.pwd)
         os.system("rm -rf source_dir target_dir source_dir* backup_dir* huge")
         _ = crypto._testing_set_PDTCRYPT_MAX_OBJ_SIZE \
@@ -1868,6 +1877,16 @@ class DeltaTarTest(BaseTest):
         fullpath = os.path.join("source_dir", testpath)
         assert not os.path.exists(fullpath)
 
+
+def fsapi_access_true (self):
+    """
+    Chicanery for testing improper use of the *os* module.
+    """
+    def yes (*_a, **_ka): return True
+    self.FSAPI_SAVED.append (("access", getattr (os, "access")))
+    setattr (os, "access", yes)
+
+
 class DeltaTar2Test(DeltaTarTest):
     '''
     Same as DeltaTar but with specific ":" mode
@@ -1941,3 +1960,9 @@ class DeltaTarAes128ConcatTest(DeltaTarTest):
     ENCRYPTION = ('some magic key', 1)
 
 
+class DeltaTarFilesystemHandlingTest(DeltaTarGzipTest):
+    '''
+    Mess with filesystem APIs.
+    '''
+    FSTEST = fsapi_access_true
+