3 from base_test import DakTestCase, fixture
7 from daklib.gpg import GpgException
8 from daklib.utils import parse_changes
9 from daklib.dak_exceptions import InvalidDscError, ParseChangesError
11 class ParseChangesTestCase(DakTestCase):
12 def assertParse(self, filename, *args):
13 return parse_changes(fixture(filename), *args)
15 class ParseDscTestCase(ParseChangesTestCase):
17 self.assertParse('dsc/1.dsc', -1, 1)
19 def test_1_ignoreErrors(self):
20 # Valid .dsc ; ignoring errors
21 self.assertParse('dsc/1.dsc', -1, 1)
24 # Missing blank line before signature body
25 self.assertParse('dsc/2.dsc', -1, 1)
27 def test_2_ignoreErrors(self):
28 # Invalid .dsc ; ignoring errors
29 self.assertParse('dsc/2.dsc', -1, 1)
32 # Missing blank line after signature header
33 self.assertParse('dsc/3.dsc', -1, 1)
36 # No blank lines at all
37 with self.assertRaises(GpgException):
38 self.assertParse('dsc/4.dsc', -1, 1)
41 # Extra blank line before signature body
42 self.assertParse('dsc/5.dsc', -1, 1)
45 # Extra blank line after signature header
46 self.assertParse('dsc/6.dsc', -1, 1)
49 # Blank file is an invalid armored GPG file
50 with self.assertRaises(GpgException):
51 self.assertParse('dsc/7.dsc', -1, 1)
55 with self.assertRaisesRegexp(ParseChangesError, "Empty changes"):
56 self.assertParse('dsc/8.dsc', -1, 1)
59 changes = self.assertParse('dsc/9.dsc', -1, 1)
60 self.assert_(changes['question'] == 'Is this a bug?')
61 self.failIf(changes.get('this'))
63 class ParseChangesTestCase(ParseChangesTestCase):
66 with self.assertRaises(GpgException):
67 self.assertParse('changes/1.changes', 1)
70 changes = self.assertParse('changes/2.changes', -1)
72 binaries = changes['binary']
74 self.assert_('krb5-ftpd' in binaries.split())
77 for filename in ('valid', 'bogus-pre', 'bogus-post'):
78 for strict_whitespace in (-1,):
79 changes = self.assertParse(
80 'changes/%s.changes' % filename,
83 self.failIf(changes.get('you'))
85 if __name__ == '__main__':