]> git.decadent.org.uk Git - dak.git/blob - tests/test_parse_changes.py
Fix incorrect update number
[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     def assertFails(self, filename, line=None, *args):
16         try:
17             self.assertParse(filename, *args)
18             self.fail('%s was not recognised as invalid' % filename)
19         except ParseChangesError:
20             pass
21         except GpgException:
22             pass
23         except InvalidDscError as actual_line:
24             if line is not None:
25                 assertEqual(actual_line, line)
26
27 class ParseDscTestCase(ParseChangesTestCase):
28     def test_1(self):
29         self.assertParse('dsc/1.dsc', -1, 1)
30
31     def test_1_ignoreErrors(self):
32         # Valid .dsc ; ignoring errors
33         self.assertParse('dsc/1.dsc', -1, 1)
34
35     def test_2(self):
36         # Missing blank line before signature body
37         self.assertParse('dsc/2.dsc', -1, 1)
38
39     def test_2_ignoreErrors(self):
40         # Invalid .dsc ; ignoring errors
41         self.assertParse('dsc/2.dsc', -1, 1)
42
43     def test_3(self):
44         # Missing blank line after signature header
45         self.assertParse('dsc/3.dsc', -1, 1)
46
47     def test_4(self):
48         # No blank lines at all
49         self.assertFails('dsc/4.dsc', -1, 1)
50
51     def test_5(self):
52         # Extra blank line before signature body
53         self.assertParse('dsc/5.dsc', -1, 1)
54
55     def test_6(self):
56         # Extra blank line after signature header
57         self.assertParse('dsc/6.dsc', -1, 1)
58
59 class ParseChangesTestCase(ParseChangesTestCase):
60     def test_1(self):
61         # Empty changes
62         self.assertFails('changes/1.changes', 5, -1)
63
64     def test_2(self):
65         changes = self.assertParse('changes/2.changes', -1)
66
67         binaries = changes['binary']
68
69         self.assert_('krb5-ftpd' in binaries.split())
70
71     def test_3(self):
72         for filename in ('valid', 'bogus-pre', 'bogus-post'):
73             for strict_whitespace in (-1,):
74                 changes = self.assertParse(
75                     'changes/%s.changes' % filename,
76                     strict_whitespace,
77                 )
78                 self.failIf(changes.get('you'))
79
80     def test_4(self):
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'))
84
85 if __name__ == '__main__':
86     unittest.main()