Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28186
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@python.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901; t=1346431828; bh=xwP42Tc+TXtXQtNQXRqdBGnbvzgeU9H/eBa8scTFlqg=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=B92G2wNfCkI9nT1Leht6STACH8vb7p5Me742R7wYqZ8hziPPFq/9VM3G8eENQvim2 3/OwmnP0JTHiVGF121Y2PU8Y8j5+9nOiFuUPbgQOuH9PxuSUYCqCmD8NU8E6su19ZW 46gZO65HEefYjzAzZEqCMpRrbcaUzz4yzCXmsr+M= |
| 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; 'from:name:chris withers': 0.09; 'os.getcwd()': 0.09; 'received:89.151': 0.09; 'received:89.151.125': 0.09; 'received:89.151.125.140': 0.09; 'received:server1.simplistix.co.uk': 0.09; 'received:simplistix.co.uk': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; "wouldn't": 0.11; 'empty"': 0.16; 'message- id:@python.org': 0.16; 'paths.': 0.16; 'received:93.89': 0.16; 'received:93.89.128': 0.16; 'received:93.89.128.162': 0.16; 'received:buzzkill.local': 0.16; 'setup(self):': 0.16; 'simplistix': 0.16; 'url:packages': 0.16; 'url:simplistix': 0.16; 'from:addr:python.org': 0.17; 'wrote:': 0.17; 'from:addr:chris': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'absolute': 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; 'chris': 0.28; 'class': 0.29; 'url:python': 0.32; 'skip:s 30': 0.33; 'url:org': 0.36; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'skip:" 10': 0.40; 'url:co': 0.66; 'received:93': 0.72; 'received:89': 0.86 |
| Date | Fri, 31 Aug 2012 17:19:10 +0100 |
| From | Chris Withers <chris@python.org> |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:5.0) Gecko/20110624 Thunderbird/5.0 |
| MIME-Version | 1.0 |
| To | Tigerstyle <laddosingh@gmail.com> |
| Subject | Re: Unittest - testing for filenames and filesize |
| References | <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> |
| In-Reply-To | <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6.1346431828.27098.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1346431828 news.xs4all.nl 6903 [2001:888:2000:d::a6]:45888 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:28186 |
Show key headers only | View raw
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Unittest - testing for filenames and filesize Tigerstyle <laddosingh@gmail.com> - 2012-08-23 04:25 -0700
Re: Unittest - testing for filenames and filesize Roy Smith <roy@panix.com> - 2012-08-23 08:28 -0400
Re: Unittest - testing for filenames and filesize Terry Reedy <tjreedy@udel.edu> - 2012-08-23 13:29 -0400
Re: Unittest - testing for filenames and filesize Roy Smith <roy@panix.com> - 2012-08-23 12:06 -0700
Re: Unittest - testing for filenames and filesize Roy Smith <roy@panix.com> - 2012-08-23 12:06 -0700
Re: Unittest - testing for filenames and filesize Tigerstyle <laddosingh@gmail.com> - 2012-08-24 09:20 -0700
Re: Unittest - testing for filenames and filesize Tigerstyle <laddosingh@gmail.com> - 2012-08-24 09:20 -0700
Re: Unittest - testing for filenames and filesize Robert Day <robertkday@gmail.com> - 2012-08-24 20:04 +0100
Re: Unittest - testing for filenames and filesize Tigerstyle <laddosingh@gmail.com> - 2012-08-26 10:36 -0700
Re: Unittest - testing for filenames and filesize Rob Day <rkd@rkd.me.uk> - 2012-08-26 18:51 +0100
Re: Unittest - testing for filenames and filesize Tigerstyle <laddosingh@gmail.com> - 2012-08-26 11:37 -0700
Re: Unittest - testing for filenames and filesize Tigerstyle <laddosingh@gmail.com> - 2012-08-26 11:37 -0700
Re: Unittest - testing for filenames and filesize Tigerstyle <laddosingh@gmail.com> - 2012-08-26 10:36 -0700
Re: Unittest - testing for filenames and filesize Chris Withers <chris@python.org> - 2012-08-31 17:19 +0100
Re: Unittest - testing for filenames and filesize 88888 Dihedral <dihedral88888@googlemail.com> - 2012-08-31 22:08 -0700
Re: Unittest - testing for filenames and filesize 88888 Dihedral <dihedral88888@googlemail.com> - 2012-08-31 22:08 -0700
csiph-web