3 from base_test import DakTestCase, fixture
7 from daklib.gpg import GpgException
8 from daklib.utils import parse_changes, check_dsc_files, build_file_list
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 changes = self.assertParse('dsc/1.dsc', -1, 1)
18 files = build_file_list(changes, 1)
19 rejmsg = check_dsc_files('1.dsc', changes, files.keys())
20 self.assertEqual(rejmsg, [])
22 def test_1_ignoreErrors(self):
23 # Valid .dsc ; ignoring errors
24 self.assertParse('dsc/1.dsc', -1, 1)
27 # Missing blank line before signature body
28 self.assertParse('dsc/2.dsc', -1, 1)
30 def test_2_ignoreErrors(self):
31 # Invalid .dsc ; ignoring errors
32 self.assertParse('dsc/2.dsc', -1, 1)
35 # Missing blank line after signature header
36 self.assertParse('dsc/3.dsc', -1, 1)
39 # No blank lines at all
40 with self.assertRaises(GpgException):
41 self.assertParse('dsc/4.dsc', -1, 1)
44 # Extra blank line before signature body
45 self.assertParse('dsc/5.dsc', -1, 1)
48 # Extra blank line after signature header
49 self.assertParse('dsc/6.dsc', -1, 1)
52 # Blank file is an invalid armored GPG file
53 with self.assertRaises(GpgException):
54 self.assertParse('dsc/7.dsc', -1, 1)
58 with self.assertRaisesRegexp(ParseChangesError, "Empty changes"):
59 self.assertParse('dsc/8.dsc', -1, 1)
62 changes = self.assertParse('dsc/9.dsc', -1, 1)
63 self.assert_(changes['question'] == 'Is this a bug?')
64 self.failIf(changes.get('this'))
67 changes = self.assertParse('dsc/10.dsc', -1, 1)
68 files = build_file_list(changes, 1)
69 rejmsg = check_dsc_files('10.dsc', changes, files.keys())
70 self.assertEqual(rejmsg, ['10.dsc: contains source files not allowed in format 1.0'])
73 class ParseChangesTestCase(ParseChangesTestCase):
76 with self.assertRaises(GpgException):
77 self.assertParse('changes/1.changes', 1)
80 changes = self.assertParse('changes/2.changes', -1)
82 binaries = changes['binary']
84 self.assert_('krb5-ftpd' in binaries.split())
87 for filename in ('valid', 'bogus-pre', 'bogus-post'):
88 for strict_whitespace in (-1,):
89 changes = self.assertParse(
90 'changes/%s.changes' % filename,
93 self.failIf(changes.get('you'))
95 if __name__ == '__main__':