summaryrefslogtreecommitdiff
path: root/tests/13_test_gbp_pq.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-11-24 00:33:54 +0100
committerGuido Günther <agx@sigxcpu.org>2012-11-24 12:20:41 +0100
commit24fdd97267ec03e0b7b94afcd5cefb56772df1e4 (patch)
tree97a80eb0439ed7cfcee2f99efc82c097c072b828 /tests/13_test_gbp_pq.py
parent95ec21a699c5fe57824e2f216aec0c43c362b803 (diff)
downloadgit-buildpackage-24fdd97267ec03e0b7b94afcd5cefb56772df1e4.tar.gz
git-buildpackage-24fdd97267ec03e0b7b94afcd5cefb56772df1e4.tar.bz2
git-buildpackage-24fdd97267ec03e0b7b94afcd5cefb56772df1e4.zip
Test gbp.pq.common.write_patch
Diffstat (limited to 'tests/13_test_gbp_pq.py')
-rw-r--r--tests/13_test_gbp_pq.py75
1 files changed, 59 insertions, 16 deletions
diff --git a/tests/13_test_gbp_pq.py b/tests/13_test_gbp_pq.py
index b4161308..83b43156 100644
--- a/tests/13_test_gbp_pq.py
+++ b/tests/13_test_gbp_pq.py
@@ -1,11 +1,25 @@
# vim: set fileencoding=utf-8 :
-
+# (C) 2012 Guido Günther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Test L{gbp.pq}"""
import os
+import logging
import unittest
-import gbp.scripts.common.pq
+import gbp.scripts.common.pq as pq
import gbp.patch_series
import tests.testutils as testutils
@@ -22,7 +36,7 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
os.path.join(os.path.abspath(os.path.curdir),
'tests/data/foo.patch'))
- gbp.scripts.common.pq.apply_and_commit_patch(self.repo, patch, None)
+ pq.apply_and_commit_patch(self.repo, patch, None)
self.assertIn('foo', self.repo.list_files())
@@ -32,8 +46,7 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
os.path.join(os.path.abspath(os.path.curdir),
'tests/data/foo.patch'))
- gbp.scripts.common.pq.apply_and_commit_patch(self.repo, patch, None,
- topic='foobar')
+ pq.apply_and_commit_patch(self.repo, patch, None, topic='foobar')
info = self.repo.get_commit_info('HEAD')
self.assertIn('Gbp-Pq-Topic: foobar', info['body'])
@@ -56,16 +69,14 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
self.add_file("debian/control",
"Maintainer: Guido Günther <gg@godiug.net>")
- c = gbp.scripts.common.pq.get_maintainer_from_control
- gbp.scripts.common.pq.apply_and_commit_patch(self.repo,
- patch,
- c)
+ c = pq.get_maintainer_from_control
+ pq.apply_and_commit_patch(self.repo, patch, c)
info = self.repo.get_commit_info('HEAD')
self.assertEqual(info['author'].email, 'gg@godiug.net')
self.assertIn('foo', self.repo.list_files())
class TestApplySinglePatch(testutils.DebianGitTestRepo):
- """Test L{gbp.pq}'s """
+ """Test L{gbp.pq}'s apply_single_patch"""
def setUp(self):
testutils.DebianGitTestRepo.setUp(self)
@@ -77,12 +88,44 @@ class TestApplySinglePatch(testutils.DebianGitTestRepo):
os.path.join(os.path.abspath(os.path.curdir),
'tests/data/foo.patch'))
- gbp.scripts.common.pq.apply_single_patch(self.repo, 'master', patch,
- None)
+ pq.apply_single_patch(self.repo, 'master', patch, None)
self.assertIn('foo', self.repo.list_files())
+class TestWritePatch(testutils.DebianGitTestRepo):
+ """Test L{gbp.pq}'s write_patch """
-
-
-
-
+ def setUp(self):
+ testutils.DebianGitTestRepo.setUp(self)
+ self.add_file('bar', 'bar')
+
+ def test_write_patch(self):
+ """Test moving a patch to it's final location"""
+
+ class opts: patch_numbers = False
+
+ # Add test file with topic:
+ msg = ("added foo\n\n"
+ "Gbp-Pq-Topic: gbptest")
+ 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')
+ self.assertEqual(expected, patchfile)
+ pq.write_patch(patchfile, self.repo.path, opts)
+ expected = os.path.join(self.repo.path,
+ 'gbptest',
+ 'added-foo.patch')
+
+ self.assertTrue(os.path.exists(expected))
+ logging.debug(file(expected).read())
+
+ # Reapply the patch to a new branch
+ self.repo.create_branch('testapply', 'HEAD^')
+ self.repo.set_branch('testapply')
+ self.repo.apply_patch(expected)
+ self.repo.commit_all("foo")
+ diff = self.repo.diff('master', 'testapply')
+ # Branches must be identical afterwards
+ self.assertEqual('', diff)