Example #1
0
 def test_move(self):
     try:
         fo = FileObject("test", temporary=True)
         fo.move("test_move")
         if not os.path.exists("test_move"):
             raise Exception("Failed to move")
     except Exception as exc:
         traceback.print_exc()
         self.fail(exc)
Example #2
0
 def test_chmod(self):
     try:
         fo = FileObject("test", temporary=True)
         fo.chmod(0o644)
         if oct(os.stat(fo.path).st_mode & 0o777) != oct(0o644):
             raise Exception("Wrong mode of file")
     except Exception as exc:
         traceback.print_exc()
         self.fail(exc)
Example #3
0
 def test_remove(self):
     try:
         fo = FileObject("test", temporary=True)
         fo.remove()
         if os.path.exists(fo.path):
             raise Exception("File has not been removed")
     except Exception as exc:
         traceback.print_exc()
         self.fail(exc)
Example #4
0
 def test_index_file(self):
     try:
         fo = FileObject("test_file", temporary=True)
         do = DirectoryObject("test_dir", temporary=True)
         fo.parent = do
         if do.index(fo) is None:
             raise Exception("Parent hasn't been set")
     except Exception as exc:
         traceback.print_exc()
         self.fail(exc)
Example #5
0
 def test_copy(self):
     try:
         fo = FileObject("test", temporary=True)
         fo_copy = fo.copy("test_copy")
         if not isinstance(fo_copy, FileObject):
             raise Exception("FileObject hasn't been returned as copy")
         if not os.path.exists("test_copy"):
             raise Exception("Failed to copy")
     except Exception as exc:
         traceback.print_exc()
         self.fail(exc)
Example #6
0
 def test_init(self):
     try:
         fo = FileObject("test", temporary=True)
         if not os.path.exists(fo.path):
             raise Exception("File has not been initialized")
     except Exception as exc:
         traceback.print_exc()
         self.fail(exc)
Example #7
0
 def test_del(self):
     try:
         fo = FileObject("test", temporary=True)
         del fo
         if os.path.exists("test"):
             raise Exception("Destructor hasn't removed all files")
     except Exception as exc:
         traceback.print_exc()
         self.fail(exc)
Example #8
0
 def test_init_from_precreated(self):
     try:
         with open("test", "w") as f:
             f.write("rambo test")
         perms = oct(os.stat("test").st_mode & 0o777)
         fo = FileObject("test", temporary=True)
         if oct(os.stat("test").st_mode & 0o777) != perms:
             raise Exception("Couldn't init from file")
     except Exception as exc:
         traceback.print_exc()
         self.fail(exc)
Example #9
0
 def test_pop_file(self):
     try:
         fo = FileObject("test_file", temporary=True)
         do = DirectoryObject("test_dir", temporary=True)
         do.append(fo)
         poped = do.pop(0)
         if not isinstance(poped, FileObject) and \
                 not isinstance(poped, DirectoryObject):
             raise Exception("FileObject/DirectoryObject hasn't "
                             "been returned as copy")
         if fo.parent == do or do.index(fo) is not None:
             raise Exception("Parent hasn't been unset")
     except Exception as exc:
         traceback.print_exc()
         self.fail(exc)