aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-12-24 11:15:30 +0100
committerGuido Günther <agx@sigxcpu.org>2011-12-26 14:02:24 +0100
commit637b87a01a9bdc95c48a6edd85db196f9c4a95a9 (patch)
treeca09e710947c3303b12554f512bac583f23391fc /tests
parentee9748eee0d05178effcdd0a40702615a4ac461a (diff)
pq.Patch: move support for parsing patch headers into Patch class
and add tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/08_test_patch.py34
-rw-r--r--tests/08_test_patch_data/patch1.diff7
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/08_test_patch.py b/tests/08_test_patch.py
new file mode 100644
index 00000000..8c25e04e
--- /dev/null
+++ b/tests/08_test_patch.py
@@ -0,0 +1,34 @@
+import os
+import unittest
+
+from gbp.pq import Patch
+
+class TestPatch(unittest.TestCase):
+ data_dir = "tests/%s_data" % __module__
+
+ def test_filename(self):
+ """Get patch information from the filename"""
+ p = Patch(os.path.join(self.data_dir, "doesnotexist.diff"))
+ self.assertEqual('doesnotexist', p.subject)
+ self.assertEqual({}, p.info)
+ p = Patch(os.path.join(self.data_dir, "doesnotexist.patch"))
+ self.assertEqual('doesnotexist', p.subject)
+ p = Patch(os.path.join(self.data_dir, "doesnotexist"))
+ self.assertEqual('doesnotexist', p.subject)
+ self.assertEqual(None, p.author)
+ self.assertEqual(None, p.email)
+ self.assertEqual(None, p.date)
+
+ def test_header(self):
+ """Get the patch information from a patch header"""
+ patchfile = os.path.join(self.data_dir, "patch1.diff")
+ self.assertTrue(os.path.exists(patchfile))
+ p = Patch(patchfile)
+ self.assertEqual('This is patch1', p.subject)
+ self.assertEqual("foo", p.author)
+ self.assertEqual("foo@example.com", p.email)
+ self.assertEqual("This is the long description.\n"
+ "It can span several lines.\n",
+ p.long_desc)
+ self.assertEqual('Sat, 24 Dec 2011 12:05:53 +0100', p.date)
+
diff --git a/tests/08_test_patch_data/patch1.diff b/tests/08_test_patch_data/patch1.diff
new file mode 100644
index 00000000..5521b73e
--- /dev/null
+++ b/tests/08_test_patch_data/patch1.diff
@@ -0,0 +1,7 @@
+From: foo <foo@example.com>
+Date: Sat, 24 Dec 2011 12:05:53 +0100
+Subject: This is
+ patch1
+
+This is the long description.
+It can span several lines.