testing -- what to do for testing code with behaviour dependant upon which files exist?
André Malo
auch-ich-m at g-kein-spam.com
Sat Apr 2 16:20:01 EST 2005
* Brian van den Broek wrote:
> The relevant part of the validation method code looks like:
>
> # self.universe_files is a list of file paths
> non_existent_files = [ x for x in self.universe_files if
> not os.path.isfile(x) ]
> if non_existent_files:
> raise Files_dont_existError, non_existent_files
>
> I can test the custom error class just fine, but I don't see how to
> test the validation method itself.
The logic is simple -- you don't want to test os.path.isfile, so mock it.
Just encapsulate the os.path.isfile call in an own method, which can be
overridden by your test.
nd
--
# André Malo, <http://pub.perlig.de/> #
More information about the Python-list
mailing list