]> git.decadent.org.uk Git - dak.git/blob - tests/test_parse_changes.py
Merge remote-tracking branch 'jcristau/formatone-no-tar-sig'
[dak.git] / tests / test_parse_changes.py
1 #!/usr/bin/env python
2
3 from base_test import DakTestCase, fixture
4
5 import unittest
6
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
10
11 class ParseChangesTestCase(DakTestCase):
12     def assertParse(self, filename, *args):
13         return parse_changes(fixture(filename), *args)
14
15 class ParseDscTestCase(ParseChangesTestCase):
16     def test_1(self):
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, [])
21
22     def test_1_ignoreErrors(self):
23         # Valid .dsc ; ignoring errors
24         self.assertParse('dsc/1.dsc', -1, 1)
25
26     def test_2(self):
27         # Missing blank line before signature body
28         self.assertParse('dsc/2.dsc', -1, 1)
29
30     def test_2_ignoreErrors(self):
31         # Invalid .dsc ; ignoring errors
32         self.assertParse('dsc/2.dsc', -1, 1)
33
34     def test_3(self):
35         # Missing blank line after signature header
36         self.assertParse('dsc/3.dsc', -1, 1)
37
38     def test_4(self):
39         # No blank lines at all
40         with self.assertRaises(GpgException):
41             self.assertParse('dsc/4.dsc', -1, 1)
42
43     def test_5(self):
44         # Extra blank line before signature body
45         self.assertParse('dsc/5.dsc', -1, 1)
46
47     def test_6(self):
48         # Extra blank line after signature header
49         self.assertParse('dsc/6.dsc', -1, 1)
50
51     def test_7(self):
52         # Blank file is an invalid armored GPG file
53         with self.assertRaises(GpgException):
54             self.assertParse('dsc/7.dsc', -1, 1)
55
56     def test_8(self):
57         # No armored contents
58         with self.assertRaisesRegexp(ParseChangesError, "Empty changes"):
59             self.assertParse('dsc/8.dsc', -1, 1)
60
61     def test_9(self):
62         changes = self.assertParse('dsc/9.dsc', -1, 1)
63         self.assert_(changes['question'] == 'Is this a bug?')
64         self.failIf(changes.get('this'))
65
66     def test_10(self):
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'])
71
72
73 class ParseChangesTestCase(ParseChangesTestCase):
74     def test_1(self):
75         # Empty changes
76         with self.assertRaises(GpgException):
77             self.assertParse('changes/1.changes', 1)
78
79     def test_2(self):
80         changes = self.assertParse('changes/2.changes', -1)
81
82         binaries = changes['binary']
83
84         self.assert_('krb5-ftpd' in binaries.split())
85
86     def test_3(self):
87         for filename in ('valid', 'bogus-pre', 'bogus-post'):
88             for strict_whitespace in (-1,):
89                 changes = self.assertParse(
90                     'changes/%s.changes' % filename,
91                     strict_whitespace,
92                 )
93                 self.failIf(changes.get('you'))
94
95 if __name__ == '__main__':
96     unittest.main()