Rev 162: Fix failing and leaking tests. in file:///net/bigmamac/Volumes/home/vila/.bazaar/plugins/usertest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Mar 18 17:24:07 GMT 2009
At file:///net/bigmamac/Volumes/home/vila/.bazaar/plugins/usertest/
------------------------------------------------------------
revno: 162
revision-id: v.ladeuil+lp at free.fr-20090318172405-g8gq68egxeqc1lv4
parent: ian.clatworthy at internode.on.net-20090311074550-4w85kl9taz2v99ah
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: usertest
timestamp: Wed 2009-03-18 18:24:05 +0100
message:
Fix failing and leaking tests.
* tests/test_archiveutil.py:
(TestEmptyArchive, TestArchiveWithOneRoot,
TestArchiveWithNoSharedRoot): Inherit from tests.TestCaseInTempDir
to avoid polluting current directory and fix setUp to call base
class.
-------------- next part --------------
=== modified file 'tests/test_archiveutil.py'
--- a/tests/test_archiveutil.py 2007-05-17 17:25:11 +0000
+++ b/tests/test_archiveutil.py 2009-03-18 17:24:05 +0000
@@ -22,42 +22,49 @@
import shutil
import tarfile
-from bzrlib.tests import TestCase
+from bzrlib import tests
import bzrlib.plugins.usertest.archiveutil as archiveutil
-class TestEmptyArchive(TestCase):
+class TestArchive(tests.TestCaseInTempDir):
def setUp(self):
+ tests.TestCaseInTempDir.setUp(self)
+ self._make_tarfile()
+ self.addCleanup(os.remove, self.tarname)
+
+
+class TestEmptyArchive(TestArchive):
+
+ def _make_tarfile(self):
self.tarname = "tmp%d.tar.gz" % (random.uniform(9000,9999))
tar = tarfile.open(self.tarname, "w:gz")
tar.close()
- def tearDown(self):
- os.remove(self.tarname)
-
def test_empty(self):
self.assertRaises(tarfile.ReadError, archiveutil.unpack_archive,
self.tarname)
-class TestArchiveWithOneRoot(TestCase):
-
- def setUp(self):
+
+class TestArchiveWithOneRoot(TestArchive):
+
+ def _make_tarfile(self):
+ self.root_dir = "root%d" % (random.uniform(10,99))
+ os.mkdir(self.root_dir)
+ self.addCleanup(shutil.rmtree, self.root_dir)
self.tarname = "tmp%d.tar.gz" % (random.uniform(9000,9999))
tar = tarfile.open(self.tarname, "w:gz")
- self.root_dir = "root%d" % (random.uniform(10,99))
- os.mkdir(self.root_dir)
- for item in ['a', 'b', 'c']:
- filename = os.path.join(self.root_dir,item)
- f = open(filename, "w")
- f.write("%s rocks\n" % item)
- f.close()
- tar.add(filename)
- tar.close()
-
- def tearDown(self):
- os.remove(self.tarname)
- shutil.rmtree(self.root_dir)
+ try:
+ for item in ['a', 'b', 'c']:
+ filename = os.path.join(self.root_dir,item)
+ f = open(filename, "w")
+ try:
+ f.write("%s rocks\n" % item)
+ finally:
+ f.close()
+ tar.add(filename)
+ finally:
+ tar.close()
def test_dir_there(self):
work_roots = archiveutil.unpack_archive(self.tarname)
@@ -82,24 +89,26 @@
for item in ['a', 'b', 'c']:
self.assertTrue(os.path.exists(os.path.join(dest,item)))
-class TestArchiveWithNoSharedRoot(TestCase):
-
- def setUp(self):
+
+class TestArchiveWithNoSharedRoot(TestArchive):
+
+ def _make_tarfile(self):
self.root_dir = "root%d" % (random.uniform(10,99))
os.mkdir(self.root_dir)
+ self.addCleanup(shutil.rmtree, self.root_dir)
self.tarname = "%s.tar.gz" % (self.root_dir)
tar = tarfile.open(self.tarname, "w:gz")
- for item in ['a', 'b', 'c']:
- filename = os.path.join(self.root_dir,item)
- f = open(filename, "w")
- f.write("%s rocks\n" % item)
- f.close()
- tar.add(filename, item)
- tar.close()
-
- def tearDown(self):
- os.remove(self.tarname)
- shutil.rmtree(self.root_dir)
+ try:
+ for item in ['a', 'b', 'c']:
+ filename = os.path.join(self.root_dir,item)
+ f = open(filename, "w")
+ try:
+ f.write("%s rocks\n" % item)
+ finally:
+ f.close()
+ tar.add(filename, item)
+ finally:
+ tar.close()
def test_dir_there(self):
work_roots = archiveutil.unpack_archive(self.tarname)
More information about the bazaar-commits
mailing list