Unittest - testing for filenames and filesize
Terry Reedy
tjreedy at udel.edu
Thu Aug 23 13:29:19 EDT 2012
On 8/23/2012 8:28 AM, Roy Smith wrote:
> I think you want to end up with something like:
>
> def test_1(self):
> "Verify creation of files is possible"
> filenames = ("this.txt", "that.txt", "the_other.txt")
> for filename in filenames:
> f = open(filename, "w")
> f.write("Some text\n")
> f.close()
> self.assertTrue(f.closed)
> dir_names = os.listdir()
> self.assertEqual(set(dir_names), set(filenames))
>
> The above code isn't tested, but it should give you the gist of what you
> need to do.
One can start with a set rather than tuple of file names.
def test_1(self):
"Verify creation of files is possible"
filenames = {"this.txt", "that.txt", "the_other.txt"}
for filename in filenames:
f = open(filename, "w")
f.write("Some text\n")
f.close()
self.assertTrue(f.closed)
dir_names = set(os.listdir())
self.assertEqual(dir_names, filenames)
--
Terry Jan Reedy
More information about the Python-list
mailing list