08_test_patch.py 2.01 KB
Newer Older
1 2 3 4
# vim: set fileencoding=utf-8 :

"""Test L{Patch} class"""

5
from . import context  # noqa: 401
6

7 8 9
import os
import unittest

10
from gbp.patch_series import Patch, Dep3Patch
11

12

13
class TestPatch(unittest.TestCase):
14
    data_dir = os.path.splitext(__file__)[0] + '_data'
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

    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)
41 42 43 44 45 46 47 48 49 50 51 52 53 54


class TestDep3Patch(unittest.TestCase):
    data_dir = os.path.splitext(__file__)[0] + '_data'

    def test_encoding(self):
        """Make sure broken encoding does no affect import"""
        patchfile = os.path.join(self.data_dir, "dep3-iso8859-1.patch")
        self.assertTrue(os.path.exists(patchfile))
        p = Dep3Patch(patchfile)
        self.assertEqual('Replace all -- in man page by \-\- to make lintian happy.', p.subject)
        self.assertEqual("Roland Rosenfeld", p.author)
        self.assertEqual("roland@debian.org", p.email)
        self.assertEqual("", p.long_desc)