Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.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; 'f.close()': 0.07; 'filename': 0.07; 'filenames': 0.07; '"w")': 0.09; 'filenames:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'tuple': 0.09; 'def': 0.10; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'roy': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'do.': 0.21; 'names.': 0.22; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'header:X-Complaints-To:1': 0.28; 'code': 0.31; 'file': 0.32; 'skip:s 30': 0.33; 'like:': 0.33; 'to:addr:python-list': 0.33; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'rather': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'end': 0.40; 'think': 0.40; 'smith': 0.71; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Unittest - testing for filenames and filesize Date: Thu, 23 Aug 2012 13:29:19 -0400 References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: 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: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345742998 news.xs4all.nl 6980 [2001:888:2000:d::a6]:51856 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27750 On 8/23/2012 8:28 AM, Roy Smith wrote: > I think you want to end up with something like: > > 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 = os.listdir() > self.assertEqual(set(dir_names), set(filenames)) > > The above code isn't tested, but it should give you the gist of what you > need to do. One can start with a set rather than tuple of file names. 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(dir_names, filenames) -- Terry Jan Reedy