aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/06_test_upstream_source.py
diff options
context:
space:
mode:
authorThomas Koch <thomas@koch.ro>2013-01-21 15:50:39 +0100
committerGuido Günther <agx@sigxcpu.org>2013-04-08 07:43:02 +0200
commit3d6b68ae541d6020ff747628b3e44196999e0a50 (patch)
treebb3f94d4f9c0af6eb3a9779dbf6bbee20a512ef0 /tests/06_test_upstream_source.py
parent92edb4eda14cf4b5fd1514feb7b81aa50456285c (diff)
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.
Diffstat (limited to 'tests/06_test_upstream_source.py')
-rw-r--r--tests/06_test_upstream_source.py40
1 files changed, 18 insertions, 22 deletions
diff --git a/tests/06_test_upstream_source.py b/tests/06_test_upstream_source.py
index 2ea94cd2..967c4fa0 100644
--- a/tests/06_test_upstream_source.py
+++ b/tests/06_test_upstream_source.py
@@ -2,6 +2,8 @@
"""Test the L{UpstreamSource} class"""
+from . import context
+
import glob
import os
import shutil
@@ -14,8 +16,8 @@ from gbp.pkg import UpstreamSource
class TestDir(unittest.TestCase):
def setUp(self):
- self.tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.')
- self.upstream_dir = os.path.join(self.tmpdir, 'test-1.0')
+ self.tmpdir = context.new_tmpdir(__name__)
+ self.upstream_dir = self.tmpdir.join('test-1.0')
os.mkdir(self.upstream_dir)
def test_directory(self):
@@ -27,8 +29,7 @@ class TestDir(unittest.TestCase):
self.assertEqual(source.guess_version(), ('test', '1.0'))
def tearDown(self):
- if not os.getenv("GBP_TESTS_NOCLEAN"):
- shutil.rmtree(self.tmpdir)
+ context.teardown()
class TestTar(unittest.TestCase):
"""Test if packing tar archives works"""
@@ -47,28 +48,24 @@ class TestTar(unittest.TestCase):
t.close()
def setUp(self):
- self.tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.')
+ self.tmpdir = context.new_tmpdir(__name__)
+ self.source = UpstreamSource(os.path.join(context.projectdir, "gbp"))
def tearDown(self):
- if not os.getenv("GBP_TESTS_NOCLEAN"):
- shutil.rmtree(self.tmpdir)
+ context.teardown()
def test_pack_tar(self):
"""Check if packing tar archives works"""
- source = UpstreamSource(os.path.abspath("gbp/"))
- target = os.path.join(self.tmpdir,
- "gbp_0.1.tar.bz2")
- repacked = source.pack(target)
+ target = self.tmpdir.join("gbp_0.1.tar.bz2")
+ repacked = self.source.pack(target)
self.assertEqual(repacked.is_orig(), True)
self.assertEqual(repacked.is_dir(), False)
self._check_tar(repacked, ["gbp/errors.py", "gbp/__init__.py"])
def test_pack_filtered(self):
"""Check if filtering out files works"""
- source = UpstreamSource(os.path.abspath("gbp/"))
- target = os.path.join(self.tmpdir,
- "gbp_0.1.tar.bz2")
- repacked = source.pack(target, ["__init__.py"])
+ target = self.tmpdir.join("gbp_0.1.tar.bz2")
+ repacked = self.source.pack(target, ["__init__.py"])
self.assertEqual(repacked.is_orig(), True)
self.assertEqual(repacked.is_dir(), False)
self._check_tar(repacked, ["gbp/errors.py"],
@@ -78,22 +75,21 @@ class TestTar(unittest.TestCase):
class TestZip(unittest.TestCase):
"""Test if unpacking zip archives works"""
def setUp(self):
- self.tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.')
- self.zipfile = os.path.join(self.tmpdir, "gbp-0.1.zip")
- z = zipfile.ZipFile(os.path.join(self.tmpdir, "gbp-0.1.zip"), "w")
- for f in glob.glob("gbp/*.py"):
+ self.tmpdir = context.new_tmpdir(__name__)
+ self.zipfile = self.tmpdir.join("gbp-0.1.zip")
+ z = zipfile.ZipFile(self.zipfile, "w")
+ for f in glob.glob(os.path.join(context.projectdir, "gbp/*.py")):
z.write(f, f, zipfile.ZIP_DEFLATED)
z.close()
def tearDown(self):
- if not os.getenv("GBP_TESTS_NOCLEAN"):
- shutil.rmtree(self.tmpdir)
+ context.teardown()
def test_unpack(self):
source = UpstreamSource(self.zipfile)
self.assertEqual(source.is_orig(), False)
self.assertEqual(source.is_dir(), False)
self.assertEqual(source.unpacked, None)
- source.unpack(self.tmpdir)
+ source.unpack(str(self.tmpdir))
self.assertNotEqual(source.unpacked, None)