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