Re: Unittest - testing for filenames and filesize

2012-08-31 Thread 88888 Dihedral
On Saturday, September 1, 2012 12:19:10 AM UTC+8, Chris Withers wrote: > On 23/08/2012 12:25, Tigerstyle wrote: > > > class FileTest(unittest.TestCase): > > > > > > def setUp(self): > > > self.origdir = os.getcwd() > > > self.dirname = tempfile.mkdtemp("testdir") > > >

Re: Unittest - testing for filenames and filesize

2012-08-31 Thread Chris Withers
On 23/08/2012 12:25, Tigerstyle wrote: class FileTest(unittest.TestCase): def setUp(self): self.origdir = os.getcwd() self.dirname = tempfile.mkdtemp("testdir") os.chdir(self.dirname) I wouldn't change directories like this, it's pretty fragile, just use absolu

Re: Unittest - testing for filenames and filesize

2012-08-26 Thread Tigerstyle
Ahh, thank you very much Rob. Fixed now. Have a great day. T kl. 19:51:54 UTC+2 søndag 26. august 2012 skrev Rob Day følgende: > On Sun, 2012-08-26 at 10:36 -0700, Tigerstyle wrote: > > > self.assertEqual(statinfo.st_size, filesize) > > > > > > I'm still getting AssertionEr

Re: Unittest - testing for filenames and filesize

2012-08-26 Thread Rob Day
On Sun, 2012-08-26 at 10:36 -0700, Tigerstyle wrote: > self.assertEqual(statinfo.st_size, filesize) > > I'm still getting AssertionError and the error says: 100 !=b' > > filesize is the character 'b' repeated one million times (the contents of the file, in other words). statinfo

Re: Unittest - testing for filenames and filesize

2012-08-26 Thread Tigerstyle
Thanks Rob, I'v modified the test_3 like this: def test_3(self): f = open("test.dat", "wb") filesize = (b'b'*100) f.write(filesize) f.close() statinfo = os.stat("test.dat") self.assertEqual(statinfo.st_size, filesize) I'm still getting

Re: Unittest - testing for filenames and filesize

2012-08-24 Thread Robert Day
On Fri, 2012-08-24 at 09:20 -0700, Tigerstyle wrote: > def test_3(self): > f = open("test.dat", "wb") > filesize = b"0"*100 > f.write(filesize) > f.close() > self.assertEqual(os.stat, filesize) > The test_3 is to test if the created binary file har

Re: Unittest - testing for filenames and filesize

2012-08-24 Thread Tigerstyle
Thank you guys, Roy and Terry. I has been great help. I still need some help. Here is the updated code: Demostration of setUp and tearDown. The tests do not actually test anything - this is a demo. """ import unittest import tempfile import shutil import glob import os class FileTest(unittest.

Re: Unittest - testing for filenames and filesize

2012-08-23 Thread Roy Smith
On Thursday, August 23, 2012 1:29:19 PM UTC-4, Terry Reedy wrote: > One can start with a set rather than tuple of file names. > filenames = {"this.txt", "that.txt", "the_other.txt"} Yeah, that's even cleaner. Just be aware, the set notation above is only available in (IIRC), 2.7 or abo

Re: Unittest - testing for filenames and filesize

2012-08-23 Thread Terry Reedy
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")

Re: Unittest - testing for filenames and filesize

2012-08-23 Thread Roy Smith
In article <6b0299df-bc24-406b-8d69-489e990d8...@googlegroups.com>, Tigerstyle wrote: > Hi. > > I need help with an assignment and I hope you guys can guide me in the right > direction. > [code elided] > 1. The test_1() method includes code to verify that the test directory > contains only th

Unittest - testing for filenames and filesize

2012-08-23 Thread Tigerstyle
Hi. I need help with an assignment and I hope you guys can guide me in the right direction. This is the code: -- """ Demostration of setUp and tearDown. The tests do not actually test anything - this is a demo. """ import unittest import tempfile import shutil import glob import