Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27728
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Unittest - testing for filenames and filesize |
| Date | 2012-08-23 08:28 -0400 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-CDABA6.08285523082012@news.panix.com> (permalink) |
| References | <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> |
In article <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com>,
Tigerstyle <laddosingh@gmail.com> wrote:
> Hi.
>
> I need help with an assignment and I hope you guys can guide me in the right
> direction.
> [code elided]
> 1. The test_1() method includes code to verify that the test directory
> contains only the files created by the for loop. Hint: You might create a set
> containing the list of three filenames, and then create a set from the
> os.listdir() method.
I'm not sure what your question is. The hint you give above pretty much
tells you what to do. The basic issue here is that you started out with
a list (well, tuple) of filenames. You can use os.listdir() to get a
list of filenames that exist in the current directory. The problem is
that you can't compare these two lists directly, because lists are
ordered. Converting both lists to sets eliminates the ordering and lets
you compare them.
> I'm new to Python programming so I don't know where to put the set in point
> 1. Before the test or under test1.
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.
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