Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'binary': 0.05; '[],': 0.07; 'bytes.': 0.07; 'f.close()': 0.07; 'filename': 0.07; 'filenames': 0.07; 'shutil': 0.07; 'unittest': 0.07; '"w")': 0.09; 'filenames:': 0.09; 'notation': 0.09; 'os.getcwd()': 0.09; 'tempfile': 0.09; 'terry': 0.09; 'to:addr:comp.lang.python': 0.09; 'tuple': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; '2.7': 0.13; 'empty"': 0.16; 'guys,': 0.16; 'reedy': 0.16; 'roy': 0.16; 'setup(self):': 0.16; 'wrote:': 0.17; 'working.': 0.17; 'tests': 0.18; 'import': 0.21; 'names.': 0.22; 'help.': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'class': 0.29; 'thursday,': 0.30; 'file': 0.32; 'skip:s 30': 0.33; 'code:': 0.33; 'received:google.com': 0.34; 'updated': 0.34; 'thanks': 0.34; 'received:209.85': 0.35; 'created': 0.36; 'anything': 0.36; 'test': 0.36; 'thank': 0.36; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'skip:" 10': 0.40; 'great': 0.64; 'here': 0.65; 'august': 0.66; 'smith': 0.71; 'million': 0.72 Newsgroups: comp.lang.python Date: Fri, 24 Aug 2012 09:20:28 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=81.166.233.176; posting-account=04fc6goAAACDYxuhiIAKatXLjxcOghf2 References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 81.166.233.176 MIME-Version: 1.0 Subject: Re: Unittest - testing for filenames and filesize From: Tigerstyle To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345825232 news.xs4all.nl 6852 [2001:888:2000:d::a6]:49274 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27810 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.TestCase): =20 def setUp(self): self.origdir =3D os.getcwd() self.dirname =3D tempfile.mkdtemp("testdir") os.chdir(self.dirname) =20 def test_1(self): "Verify creation of files is possible" filenames =3D {"this.txt", "that.txt", "the_other.txt"}=20 for filename in filenames:=20 f =3D open(filename, "w") f.write("Some text\n") f.close() self.assertTrue(f.closed) dir_names =3D set(os.listdir('.'))=20 self.assertEqual(set(dir_names), set(filenames))=20 =20 def test_2(self): "Verify that current directory is empty" self.assertEqual(glob.glob("*"), [], "Directory not empty") =20 def test_3(self): f =3D open("test.dat", "wb") filesize =3D b"0"*1000000 f.write(filesize) f.close() self.assertEqual(os.stat, filesize) def tearDown(self): os.chdir(self.origdir) shutil.rmtree(self.dirname 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? =20 Thanks T kl. 21:06:29 UTC+2 torsdag 23. august 2012 skrev Roy Smith f=F8lgende: > On Thursday, August 23, 2012 1:29:19 PM UTC-4, Terry Reedy wrote: >=20 >=20 >=20 > > One can start with a set rather than tuple of file names. >=20 > > filenames =3D {"this.txt", "that.txt", "the_other.txt"} >=20 >=20 >=20 > Yeah, that's even cleaner. Just be aware, the set notation above is only= available in (IIRC), 2.7 or above.