unittest of file-reading function

2005-10-18 Thread Helge Stenstroem
Say I have a function def f(filename): result = openFileAndProcessContents(filename) return result Can that function be unit tested without having a real file as input? Something along the lines of import unittest class tests(unittest.TestCase): def test1(self): fileContents

Re: unittest of file-reading function

2005-10-18 Thread Peter Hansen
Helge Stenstroem wrote: Say I have a function def f(filename): result = openFileAndProcessContents(filename) return result Can that function be unit tested without having a real file as input? Something along the lines of import unittest class tests(unittest.TestCase):

Re: unittest of file-reading function

2005-10-18 Thread Kent Johnson
Helge Stenstroem wrote: Say I have a function def f(filename): result = openFileAndProcessContents(filename) return result Can that function be unit tested without having a real file as input? If you can refactor openFileAndProcessContents() so it looks like this: def

Re: unittest of file-reading function

2005-10-18 Thread shafran
Hi! You can use tempfile.mktemp(), then write test contents to this temp file, pass it to your function, unlink tempfile. you can create / unlink temp file in setUp() / tearDown() methods. Alexander. -- http://mail.python.org/mailman/listinfo/python-list

Re: unittest of file-reading function

2005-10-18 Thread André Malo
* Helge Stenstroem wrote: Say I have a function def f(filename): result = openFileAndProcessContents(filename) return result Can that function be unit tested without having a real file as input? Something along the lines of import unittest class tests(unittest.TestCase):