I use py.test for unit testing. I have something just like this:
Class Site(object):
def set_path(self):
"""Checks if the blog folder exists. Creates new folder if necessary."""
if not os.path.isdir(self.user_dir):
print "Creating new directory:", self.user_dir
os.mkdir(self.user_dir)
else:
print "\n**", self.user, "directory already exists."
How can I unit test this without touching the file system?
Is there a general rule of thumb when dealing with such problems?
I've thought about it for a long time, and I cannot think of a solution.
My application will contain many file system accesses, and I don't know how to incorporate those methods when unit testing.
I want to specifically test that a folder is created in the correct path. The path is self.user_dir
.
I also have a download function, that downloads an image into self.user_dir
. I want to test that the image is downloaded. How would one go about testing this?