Unittest - testing for filenames and filesize

Tigerstyle laddosingh at gmail.com
Sun Aug 26 13:36:03 EDT 2012


Thanks Rob,

I'v modified the test_3 like this:


    def test_3(self):
        f = open("test.dat", "wb")
        filesize = (b'b'*1000000)
        f.write(filesize)
        f.close()
        statinfo = os.stat("test.dat")
        self.assertEqual(statinfo.st_size, filesize)
    
I'm still getting AssertionError and the error says: 1000000 !=b'

Help appreciated.

T 

kl. 21:04:54 UTC+2 fredag 24. august 2012 skrev Robert Day følgende:
> On Fri, 2012-08-24 at 09:20 -0700, Tigerstyle wrote:
> 
> 
> 
> >     def test_3(self):
> 
> >         f = open("test.dat", "wb")
> 
> >         filesize = b"0"*1000000
> 
> >         f.write(filesize)
> 
> >         f.close()
> 
> >         self.assertEqual(os.stat, filesize)
> 
> 
> 
> > The test_3 is to test if the created binary file har the size of 1 million bytes. Somehow it is not working. Any suggestions?
> 
> >  
> 
> 
> 
> rob at rivertam:~$ python
> 
> Python 2.7.3 (default, Jul 24 2012, 10:05:38) 
> 
> [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> import os
> 
> >>> os.stat
> 
> <built-in function stat>
> 
> >>> 
> 
> 
> 
> So that's what 'os.stat' is. Why are you testing whether that's equal to
> 
> b"0"*1000000?
> 
> 
> 
> (You may find the documentation on os.stat at
> 
> http://docs.python.org/library/os.html#os.stat helpful; it's a function
> 
> which takes a path as its argument, and returns an object with some
> 
> relevant attributes.)



More information about the Python-list mailing list