From 3d6b68ae541d6020ff747628b3e44196999e0a50 Mon Sep 17 00:00:00 2001 From: Thomas Koch Date: Mon, 21 Jan 2013 15:50:39 +0100 Subject: tests: Use tempfile.mkdtemp to create temp dirs for tests This puts test dirs below /tmp which often is a tmpfs. All tests include the context module which consolidates tmpdir creation and cleanup, undoes a chdir in teardown and silences log messages. --- tests/02_test_upstream_source_tar_unpack.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tests/02_test_upstream_source_tar_unpack.py') diff --git a/tests/02_test_upstream_source_tar_unpack.py b/tests/02_test_upstream_source_tar_unpack.py index 650dc2ae..97bf76bb 100644 --- a/tests/02_test_upstream_source_tar_unpack.py +++ b/tests/02_test_upstream_source_tar_unpack.py @@ -2,14 +2,17 @@ """Test L{UpstreamSource}'s tarball unpack""" +from . import context + import os import shutil import tarfile import tempfile +import unittest -import gbp.deb +import gbp.pkg -class TestUnpack: +class TestUnpack(unittest.TestCase): """Make sure we unpack gzip and bzip2 archives correctly""" archive_prefix = "archive" @@ -34,17 +37,15 @@ class TestUnpack: return name, filelist def setUp(self): - self.dir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.') - self.top = os.path.abspath(os.curdir) - os.chdir(self.dir) + self.dir = context.new_tmpdir(__name__) + self.top = context.projectdir + context.chdir(self.dir) self.archives = {} for ext in [ "gz", "bz2" ]: self.archives[ext] = self._create_archive(ext) def tearDown(self): - os.chdir(self.top) - if not os.getenv("GBP_TESTS_NOCLEAN"): - shutil.rmtree(self.dir) + context.teardown() def test_upstream_source_type(self): for (comp, archive) in self.archives.iteritems(): -- cgit v1.2.3