Answer by Herbert Lee for How to do unit testing of functions writing files...
If you can use it, I'd strongly recommend using the following library: http://pyfakefs.orgpyfakefs creates an in-memory fake filesystem, and patches all filesystem accesses with accesses to the fake...
View ArticleAnswer by Enrico Marchesin for How to do unit testing of functions writing...
I always try to avoid writing files to disk, even if it's a temporary folder dedicated to my tests: not actually touching the disk makes your tests much faster, especially if you interact with files a...
View ArticleAnswer by tbc0 for How to do unit testing of functions writing files using...
import filecmpThenself.assertTrue(filecmp.cmp(path1, path2))
View ArticleAnswer by jan for How to do unit testing of functions writing files using...
Based on suggestions I did the following.class MyTestCase(unittest.TestCase): def assertFilesEqual(self, first, second, msg=None): first_f = open(first) first_str = first_f.read() second_f =...
View ArticleAnswer by gotgenes for How to do unit testing of functions writing files...
I prefer to have output functions explicitly accept a file handle (or file-like object), rather than accept a file name and opening the file themselves. This way, I can pass a StringIO object to the...
View ArticleAnswer by Don Kirkby for How to do unit testing of functions writing files...
You could separate the content generation from the file handling. That way, you can test that the content is correct without having to mess around with temporary files and cleaning them up afterward.If...
View ArticleAnswer by Ned Batchelder for How to do unit testing of functions writing...
The simplest thing is to write the output file, then read its contents, read the contents of the gold (expected) file, and compare them with simple string equality. If they are the same, delete the...
View ArticleHow to do unit testing of functions writing files using Python's 'unittest'
I have a Python function that writes an output file to disk.I want to write a unit test for it using Python's unittest module.How should I assert equality of files? I would like to get an error if the...
View Article
More Pages to Explore .....