aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/13_test_gbp_pq.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/13_test_gbp_pq.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/13_test_gbp_pq.py')
-rw-r--r--tests/13_test_gbp_pq.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/tests/13_test_gbp_pq.py b/tests/13_test_gbp_pq.py
index bcfb9bc7..10d5a777 100644
--- a/tests/13_test_gbp_pq.py
+++ b/tests/13_test_gbp_pq.py
@@ -15,6 +15,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Test L{gbp.pq}"""
+from . import context
+
import os
import logging
import unittest
@@ -32,9 +34,7 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
def test_apply_and_commit_patch(self):
"""Test applying a single patch"""
- patch = gbp.patch_series.Patch(
- os.path.join(os.path.abspath(os.path.curdir),
- 'tests/data/foo.patch'))
+ patch = gbp.patch_series.Patch(_patch_path('foo.patch'))
pq.apply_and_commit_patch(self.repo, patch, None)
self.assertIn('foo', self.repo.list_files())
@@ -42,9 +42,7 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
def test_topic(self):
"""Test if setting a topic works"""
- patch = gbp.patch_series.Patch(
- os.path.join(os.path.abspath(os.path.curdir),
- 'tests/data/foo.patch'))
+ patch = gbp.patch_series.Patch(_patch_path('foo.patch'))
pq.apply_and_commit_patch(self.repo, patch, None, topic='foobar')
info = self.repo.get_commit_info('HEAD')
@@ -56,9 +54,8 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
Check if we parse the author from debian control
if it's missing.
"""
- patch = gbp.patch_series.Patch(
- os.path.join(os.path.abspath(os.path.curdir),
- 'tests/data/foo.patch'))
+
+ patch = gbp.patch_series.Patch(_patch_path('foo.patch'))
# Overwrite data parsed from patch:
patch.author
@@ -84,9 +81,8 @@ class TestApplySinglePatch(testutils.DebianGitTestRepo):
def test_apply_single_patch(self):
"""Test applying a single patch"""
- patch = gbp.patch_series.Patch(
- os.path.join(os.path.abspath(os.path.curdir),
- 'tests/data/foo.patch'))
+
+ patch = gbp.patch_series.Patch(_patch_path('foo.patch'))
pq.apply_single_patch(self.repo, 'master', patch, None)
self.assertIn('foo', self.repo.list_files())
@@ -98,6 +94,9 @@ class TestWritePatch(testutils.DebianGitTestRepo):
testutils.DebianGitTestRepo.setUp(self)
self.add_file('bar', 'bar')
+ def tearDown(self):
+ context.teardown()
+
def test_write_patch(self):
"""Test moving a patch to it's final location"""
@@ -109,9 +108,9 @@ class TestWritePatch(testutils.DebianGitTestRepo):
self.add_file('foo', 'foo', msg)
# Write it out as patch and check it's existence
- d = os.getcwd()
- patchfile = self.repo.format_patches('HEAD^', 'HEAD', d)[0]
- expected = os.path.join(d, '0001-added-foo.patch')
+ d = context.new_tmpdir(__name__)
+ patchfile = self.repo.format_patches('HEAD^', 'HEAD', str(d))[0]
+ expected = os.path.join(str(d), '0001-added-foo.patch')
self.assertEqual(expected, patchfile)
pq.write_patch(patchfile, self.repo.path, opts)
expected = os.path.join(self.repo.path,
@@ -129,3 +128,6 @@ class TestWritePatch(testutils.DebianGitTestRepo):
diff = self.repo.diff('master', 'testapply')
# Branches must be identical afterwards
self.assertEqual('', diff)
+
+def _patch_path(name):
+ return os.path.join(context.projectdir, 'tests/data', name)