From a76fa564e461c310360575c74dc8bfba3d1bda74 Mon Sep 17 00:00:00 2001 From: Siddharth Ravikumar Date: Wed, 4 Mar 2015 21:26:42 -0500 Subject: renamed combox.file.rm_dir -> combox.file.rm_path rm_path deletes a file or an empty directory. updated the test for it too. modified: tests/file_test.py --- combox/file.py | 14 ++++++++++---- tests/file_test.py | 14 +++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/combox/file.py b/combox/file.py index 461d313..1e680c6 100644 --- a/combox/file.py +++ b/combox/file.py @@ -128,13 +128,19 @@ def rm_nodedir(directory, config): for node in nodes: dir_path = path.join(node, rel_path) - rm_dir(dir_path) + rm_path(dir_path) -def rm_dir(directory): - """Removes directory""" +def rm_path(fpath): + """Removes fpath. + + fpath can be a file or a empty directory. + """ try: - os.rmdir(directory) + if path.isfile(fpath): + os.remove(fpath) + else: + os.rmdir(fpath) except OSError, e: print e, "Something wrong. report bug to sravik@bgsu.edu" diff --git a/tests/file_test.py b/tests/file_test.py index ccd54b0..0e19e60 100644 --- a/tests/file_test.py +++ b/tests/file_test.py @@ -22,6 +22,7 @@ from hashlib import sha512 from glob import glob from nose.tools import * from os import path, remove +from shutil import copyfile from combox.config import get_nodedirs from combox.crypto import split_and_encrypt @@ -154,13 +155,20 @@ class TestFile(object): assert foo_nodedir == node_path(foo_dir, self.config) - def test_rmdir(self): - """Tests rm_dir function""" + def test_rmpath(self): + """Tests rm_path function""" new_dir = path.join(self.config['combox_dir'], 'fooius') os.mkdir(new_dir) assert path.isdir(new_dir) - rm_dir(new_dir) + new_file = path.join(new_dir, 'fooius.ext') + copyfile(self.TEST_FILE, new_file) + assert path.isfile(new_file) + + rm_path(new_file) + assert not path.isfile(new_file) + + rm_path(new_dir) assert not path.isdir(new_dir) -- cgit v1.2.3