Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.07; 'f.close()': 0.07; 'filename': 0.07; 'python': 0.09; '"w")': 0.09; 'os.getcwd()': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; "wouldn't": 0.11; 'stack': 0.15; 'daemons': 0.16; 'empty"': 0.16; 'iterators': 0.16; 'paths.': 0.16; 'setup(self):': 0.16; 'simplistix': 0.16; 'url:packages': 0.16; 'url:simplistix': 0.16; 'wrote:': 0.17; 'cheers,': 0.23; 'absolute': 0.23; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'supported': 0.26; 'cc:addr:gmail.com': 0.27; 'tree': 0.27; 'chris': 0.28; 'class': 0.29; 'url:python': 0.32; 'could': 0.32; 'skip:s 30': 0.33; 'received:google.com': 0.34; 'from:addr:googlemail.com': 0.35; 'received:209.85': 0.35; 'url:org': 0.36; 'listing': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'skip:" 10': 0.40; 'services': 0.64; 'url:co': 0.66 Newsgroups: comp.lang.python Date: Fri, 31 Aug 2012 22:08:56 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.32.215; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 123.192.32.215 MIME-Version: 1.0 Subject: Re: Unittest - testing for filenames and filesize From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org, Tigerstyle X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 81 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1346476139 news.xs4all.nl 6919 [2001:888:2000:d::a6]:36760 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28203 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") > > > os.chdir(self.dirname) > > > > I wouldn't change directories like this, it's pretty fragile, just use > > absolute paths. > > > > > def test_1(self): > > > "Verify creation of files is possible" > > > for filename in ("this.txt", "that.txt", "the_other.txt"): > > > f = open(filename, "w") > > > f.write("Some text\n") > > > f.close() > > > self.assertTrue(f.closed) > > > > > > def test_2(self): > > > "Verify that current directory is empty" > > > self.assertEqual(glob.glob("*"), [], "Directory not empty") > > > > > > def tearDown(self): > > > os.chdir(self.origdir) > > > shutil.rmtree(self.dirname) > > > > Seeing this, you might find the following tools useful: > > > > http://packages.python.org/testfixtures/files.html > > > > cheers, > > > > Chris > > > > -- > > Simplistix - Content Management, Batch Processing & Python Consulting > > - http://www.simplistix.co.uk Well, I am thinking that the directory tree listing services or daemons supported by the OS by some iterators could be better than the stack based model.