I'm trying to understand how to use unittest framework of python
I have a piece of code that looks like this --
while True:
filename = raw_input('Enter file')
if os.path.exists(filename):
break
else:
print "That file does not exist"
return filename
Can somebody help me out in developing the unittest module to test this. I'm asking this question in order to learn how to use unittesting (i'm trying to learn TTD: Test-Driven Development)
So far I've come up with this ... import unittest import os.path
class TestFunctions(unittest.TestCase):
def setUp(self):
self.prompt = 'Enter filename: '
def test_get_file(self):
# TODO make sure empty filename argument requests for new filename
filename = find_author.get_valid_filename(self.prompt)
self.assertTrue(<EXPRESSION?>)
# TODO make sure valid filename returns the "filename"
# TODO make sure invalid filename prompts that file does not exit and requests new filename
if name == "main": unittest.main()