]> git.decadent.org.uk Git - dak.git/blob - tests/test_parse_changes.py
dep11: Validate .xz compressed files as well
[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
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         self.assertParse('dsc/1.dsc', -1, 1)
18
19     def test_1_ignoreErrors(self):
20         # Valid .dsc ; ignoring errors
21         self.assertParse('dsc/1.dsc', -1, 1)
22
23     def test_2(self):
24         # Missing blank line before signature body
25         self.assertParse('dsc/2.dsc', -1, 1)
26
27     def test_2_ignoreErrors(self):
28         # Invalid .dsc ; ignoring errors
29         self.assertParse('dsc/2.dsc', -1, 1)
30
31     def test_3(self):
32         # Missing blank line after signature header
33         self.assertParse('dsc/3.dsc', -1, 1)
34
35     def test_4(self):
36         # No blank lines at all
37         with self.assertRaises(GpgException):
38             self.assertParse('dsc/4.dsc', -1, 1)
39
40     def test_5(self):
41         # Extra blank line before signature body
42         self.assertParse('dsc/5.dsc', -1, 1)
43
44     def test_6(self):
45         # Extra blank line after signature header
46         self.assertParse('dsc/6.dsc', -1, 1)
47
48     def test_7(self):
49         # Blank file is an invalid armored GPG file
50         with self.assertRaises(GpgException):
51             self.assertParse('dsc/7.dsc', -1, 1)
52
53     def test_8(self):
54         # No armored contents
55         with self.assertRaisesRegexp(ParseChangesError, "Empty changes"):
56             self.assertParse('dsc/8.dsc', -1, 1)
57
58     def test_9(self):
59         changes = self.assertParse('dsc/9.dsc', -1, 1)
60         self.assert_(changes['question'] == 'Is this a bug?')
61         self.failIf(changes.get('this'))
62
63 class ParseChangesTestCase(ParseChangesTestCase):
64     def test_1(self):
65         # Empty changes
66         with self.assertRaises(GpgException):
67             self.assertParse('changes/1.changes', 1)
68
69     def test_2(self):
70         changes = self.assertParse('changes/2.changes', -1)
71
72         binaries = changes['binary']
73
74         self.assert_('krb5-ftpd' in binaries.split())
75
76     def test_3(self):
77         for filename in ('valid', 'bogus-pre', 'bogus-post'):
78             for strict_whitespace in (-1,):
79                 changes = self.assertParse(
80                     'changes/%s.changes' % filename,
81                     strict_whitespace,
82                 )
83                 self.failIf(changes.get('you'))
84
85 if __name__ == '__main__':
86     unittest.main()