Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27810
| 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 | <laddosingh@gmail.com> |
| 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 | <mailman.3728.1345748791.4697.python-list@python.org> |
| 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> <roy-CDABA6.08285523082012@news.panix.com> <mailman.3724.1345742998.4697.python-list@python.org> <mailman.3728.1345748791.4697.python-list@python.org> |
| 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 <laddosingh@gmail.com> |
| 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 <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> |
| Message-ID | <mailman.3760.1345825232.4697.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
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):
def setUp(self):
self.origdir = os.getcwd()
self.dirname = tempfile.mkdtemp("testdir")
os.chdir(self.dirname)
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")
f.write("Some text\n")
f.close()
self.assertTrue(f.closed)
dir_names = set(os.listdir('.'))
self.assertEqual(set(dir_names), set(filenames))
def test_2(self):
"Verify that current directory is empty"
self.assertEqual(glob.glob("*"), [], "Directory not empty")
def test_3(self):
f = open("test.dat", "wb")
filesize = 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?
Thanks
T
kl. 21:06:29 UTC+2 torsdag 23. august 2012 skrev Roy Smith følgende:
> 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 above.
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