summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-03-04 20:49:31 -0500
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-03-04 20:49:31 -0500
commit51b7feef964f77d589fd9e305f4de3f9cf88fb83 (patch)
tree9841d81ccdb3226b6f58e09031fe5e03cbbd3007
parent7c612e9520aa7d1c41e0aa9eafc0cf00cebb7180 (diff)
new function combox.file.mk_dir
wrote test for it too. modified: combox/file.py modified: tests/file_test.py
-rw-r--r--combox/file.py8
-rw-r--r--tests/file_test.py22
2 files changed, 30 insertions, 0 deletions
diff --git a/combox/file.py b/combox/file.py
index 43ce5af..3990166 100644
--- a/combox/file.py
+++ b/combox/file.py
@@ -110,6 +110,14 @@ def mk_nodedir(directory, config):
print e, "Something wrong. report bug to sravik@bgsu.edu"
+def mk_dir(directory):
+ """Creates directory"""
+ try:
+ os.mkdir(directory)
+ except OSError, e:
+ print e, "Something wrong. report bug to sravik@bgsu.edu"
+
+
def rm_nodedir(directory, config):
"""
Removes directory `directory' inside the nodes.
diff --git a/tests/file_test.py b/tests/file_test.py
index b740704..ccd54b0 100644
--- a/tests/file_test.py
+++ b/tests/file_test.py
@@ -42,6 +42,10 @@ class TestFile(object):
FILES_DIR = self.config['combox_dir']
self.TEST_FILE = path.join(FILES_DIR,'the-red-star.jpg')
+ # files that have to be removed at the end of this test class
+ # should be appended to this list.
+ self.purge_list = []
+
def test_split(self):
"""Test to split, glue and create a copy of the image file from the
@@ -160,6 +164,17 @@ class TestFile(object):
assert not path.isdir(new_dir)
+ def test_mkdir(self):
+ """Tests mk_dir function."""
+ new_dir = path.join(self.config['combox_dir'], 'barius')
+ mk_dir(new_dir)
+
+ assert path.isdir(new_dir)
+
+ # add it to purge list
+ self.purge_list.append(new_dir)
+
+
@classmethod
def teardown_class(self):
"""Purge the mess created by this test."""
@@ -167,3 +182,10 @@ class TestFile(object):
rm_shards(self.TEST_FILE, self.config)
rm_nodedirs(self.config)
rm_configdir()
+
+ for f in self.purge_list:
+ if path.exists(f) and path.isfile(f):
+ os.remove(f)
+ elif path.exists(f) and path.isdir(f):
+ purge_dir(f)
+ os.rmdir(f)