~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Lib/test/test_tarfile.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
def md5sum(data):
28
28
    return md5(data).hexdigest()
29
29
 
30
 
def path(path):
31
 
    return test_support.findfile(path)
32
 
 
33
 
TEMPDIR = os.path.join(tempfile.gettempdir(), "test_tarfile_tmp")
34
 
tarname = path("testtar.tar")
 
30
TEMPDIR = os.path.abspath(test_support.TESTFN)
 
31
tarname = test_support.findfile("testtar.tar")
35
32
gzipname = os.path.join(TEMPDIR, "testtar.tar.gz")
36
33
bz2name = os.path.join(TEMPDIR, "testtar.tar.bz2")
37
34
tmpname = os.path.join(TEMPDIR, "tmp.tar")
267
264
            self.assertEqual(tarinfo.mtime, os.path.getmtime(path))
268
265
        tar.close()
269
266
 
 
267
    def test_init_close_fobj(self):
 
268
        # Issue #7341: Close the internal file object in the TarFile
 
269
        # constructor in case of an error. For the test we rely on
 
270
        # the fact that opening an invalid file raises a ReadError.
 
271
        invalid = os.path.join(TEMPDIR, "invalid")
 
272
        open(invalid, "wb").write("foo")
 
273
 
 
274
        try:
 
275
            tar = object.__new__(tarfile.TarFile)
 
276
            try:
 
277
                tar.__init__(invalid)
 
278
            except tarfile.ReadError:
 
279
                self.assertTrue(tar.fileobj.closed)
 
280
            else:
 
281
                self.fail("ReadError not raised")
 
282
        finally:
 
283
            os.remove(invalid)
 
284
 
270
285
 
271
286
class StreamReadTest(ReadTest):
272
287
 
1165
1180
 
1166
1181
 
1167
1182
def test_main():
1168
 
    if not os.path.exists(TEMPDIR):
1169
 
        os.mkdir(TEMPDIR)
 
1183
    os.makedirs(TEMPDIR)
1170
1184
 
1171
1185
    tests = [
1172
1186
        UstarReadTest,