def test_chmod(self): try: do = DirectoryObject("test", temporary=True) do.chmod(0o644) if oct(os.stat(do.path).st_mode & 0o777) != oct(0o644): raise Exception("Wrong mode of moved directory") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_remove(self): try: do = DirectoryObject("test", temporary=True) do.remove() if os.path.exists(do.path): raise Exception("Directory has not been removed") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_move(self): try: do = DirectoryObject("test", temporary=True) do.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)
def test_append_dir(self): try: do1 = DirectoryObject("test_dir1", temporary=True) do2 = DirectoryObject("test_dir2", temporary=True) do2.append(do1) if do1.parent != do2 or do2.index(do1) is None: raise Exception("Parent hasn't been set") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_insert_file(self): try: fo = FileObject("test_file", temporary=True) do = DirectoryObject("test_dir", temporary=True) do.insert(0, fo) if fo.parent != do or do.index(fo) is None: raise Exception("Parent hasn't been set") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_index_file_path(self): try: fo = FileObject("test_file", temporary=True) do = DirectoryObject("test_dir", temporary=True) fo.parent = do if do.index(path=fo.path) is None: raise Exception("Parent hasn't been set") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_copy(self): try: do = DirectoryObject("test", temporary=True) do_copy = do.copy("test_copy") if not isinstance(do_copy, DirectoryObject): raise Exception("DirectoryObject 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)
def test_init(self): try: do = DirectoryObject("test", temporary=True) if not os.path.exists(do.path): raise Exception("Directory has not been initialized") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_del(self): try: do = DirectoryObject("test", temporary=True) del do if os.path.exists("test"): raise Exception("Destructor hasn't removed all directories") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_unparent_dir(self): try: do1 = DirectoryObject("test_dir1", temporary=True) do2 = DirectoryObject("test_dir2", temporary=True) do1.parent = do2 do1.unparent() if do1.parent == do2 or do2.index(do1) is not None: raise Exception("Parent hasn't been unset") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_init_from_precreated(self): try: os.mkdir("test") perms = oct(os.stat("test").st_mode & 0o777) do = DirectoryObject("test", temporary=True) if oct(os.stat("test").st_mode & 0o777) != perms: raise Exception("Couldn't init from directory") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_index_dir_path(self): try: do1 = DirectoryObject("test_dir1", temporary=True) do2 = DirectoryObject("test_dir2", temporary=True) do1.parent = do2 if do2.index(path=do1.path) is None: raise Exception("Parent hasn't been set") except Exception as exc: traceback.print_exc() self.fail(exc)
def test_pop_dir(self): try: do1 = DirectoryObject("test_dir1", temporary=True) do2 = DirectoryObject("test_dir2", temporary=True) do2.append(do1) poped = do2.pop(0) if not isinstance(poped, FileObject) and \ not isinstance(poped, DirectoryObject): raise Exception("FileObject/DirectoryObject hasn't " "been returned as copy") if do1.parent == do2 or do2.index(do1) is not None: raise Exception("Parent hasn't been unset") except Exception as exc: traceback.print_exc() self.fail(exc)
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)