def test_delete_directory(self, dir_function): basepath = dir_function.path directory = 'a' file_manager.create_package_directories(basepath, directory) path = os.path.join(basepath, directory) errors = file_manager.delete_directory(path) assert errors == [] assert not os.path.isdir(path)
def delete_directory(self, dir_name, file_type): errors = [] base_path = self.element_directory_path(file_type) relpath = os.sep.join(dir_name.split('.')) fullpath = os.path.join(base_path, relpath) if not os.path.isdir(fullpath): errors.append('Directory {} does not exist'.format(relpath)) else: errors = file_manager.delete_directory(fullpath) return errors
def test_delete_directory_with_files_and_folders(self, dir_function, test_utils): basepath = dir_function.path directory = 'a' file_manager.create_package_directories(basepath, directory) file_manager.create_package_directories(os.path.join(basepath, directory), 'foo') test_utils.create_empty_file(os.path.join(basepath, directory), 'bar.txt') path = os.path.join(basepath, directory) errors = file_manager.delete_directory(path) assert errors == [] assert not os.path.isdir(path)
def test_delete_directory_a_child_file_is_open(self, dir_function, test_utils): basepath = dir_function.path directory = 'a' file_manager.create_package_directories(basepath, directory) filename_one = test_utils.create_empty_file(os.path.join(basepath, directory), 'foo.txt') filename_two = test_utils.create_empty_file(os.path.join(basepath, directory), 'bar.txt') path = os.path.join(basepath, directory) with open(filename_one): errors = file_manager.delete_directory(path) assert errors == ['Error: PermissionError'] assert os.path.isdir(path) # open file was not removed assert os.path.isfile(filename_one) # not open file was removed assert not os.path.isfile(filename_two)
def delete_project(project_name): """Delete an entire project. DANGER """ return file_manager.delete_directory(Project(project_name).path)
def test_delete_directory_does_not_exist(self, dir_function): basepath = dir_function.path directory = 'a' path = os.path.join(basepath, directory) errors = file_manager.delete_directory(path) assert errors == ['Directory does not exist']