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 def assertFails(self, filename, line=None, *args):
17 self.assertParse(filename, *args)
18 self.fail('%s was not recognised as invalid' % filename)
19 except ParseChangesError:
23 except InvalidDscError as actual_line:
25 assertEqual(actual_line, line)
27 class ParseDscTestCase(ParseChangesTestCase):
29 self.assertParse('dsc/1.dsc', -1, 1)
31 def test_1_ignoreErrors(self):
32 # Valid .dsc ; ignoring errors
33 self.assertParse('dsc/1.dsc', -1, 1)
36 # Missing blank line before signature body
37 self.assertParse('dsc/2.dsc', -1, 1)
39 def test_2_ignoreErrors(self):
40 # Invalid .dsc ; ignoring errors
41 self.assertParse('dsc/2.dsc', -1, 1)
44 # Missing blank line after signature header
45 self.assertParse('dsc/3.dsc', -1, 1)
48 # No blank lines at all
49 self.assertFails('dsc/4.dsc', -1, 1)
52 # Extra blank line before signature body
53 self.assertParse('dsc/5.dsc', -1, 1)
56 # Extra blank line after signature header
57 self.assertParse('dsc/6.dsc', -1, 1)
59 class ParseChangesTestCase(ParseChangesTestCase):
62 self.assertFails('changes/1.changes', 5, -1)
65 changes = self.assertParse('changes/2.changes', -1)
67 binaries = changes['binary']
69 self.assert_('krb5-ftpd' in binaries.split())
72 for filename in ('valid', 'bogus-pre', 'bogus-post'):
73 for strict_whitespace in (-1,):
74 changes = self.assertParse(
75 'changes/%s.changes' % filename,
78 self.failIf(changes.get('you'))
81 changes = self.assertParse('changes/two-beginnings.changes', -1, 1)
82 self.assert_(changes['question'] == 'Is this a bug?')
83 self.failIf(changes.get('this'))
85 if __name__ == '__main__':