]> git.decadent.org.uk Git - dak.git/blob - tests/test_formats.py
debianqueued: No early notifications
[dak.git] / tests / test_formats.py
1 #!/usr/bin/env python
2
3 from base_test import DakTestCase
4
5 import unittest
6
7 from daklib.formats import parse_format, validate_changes_format
8 from daklib.dak_exceptions import UnknownFormatError
9
10 class ParseFormatTestCase(DakTestCase):
11     def assertParse(self, format, expected):
12         self.assertEqual(parse_format(format), expected)
13
14     def assertParseFail(self, format):
15         self.assertRaises(
16             UnknownFormatError,
17             lambda: parse_format(format)
18         )
19
20     def testParse(self):
21         self.assertParse('1.0', (1, 0))
22
23     def testEmpty(self):
24         self.assertParseFail('')
25         self.assertParseFail(' ')
26         self.assertParseFail('  ')
27
28     def textText(self):
29         self.assertParse('1.2 (three)', (1, 2, 'three'))
30         self.assertParseFail('0.0 ()')
31
32 class ValidateChangesFormat(DakTestCase):
33     def assertValid(self, changes, field='files'):
34         validate_changes_format(changes, field)
35
36     def assertInvalid(self, *args, **kwargs):
37         self.assertRaises(
38             UnknownFormatError,
39             lambda: self.assertValid(*args, **kwargs)
40         )
41
42     ##
43
44     def testBinary(self):
45         self.assertValid((1, 5))
46         self.assertValid((1, 8))
47         self.assertInvalid((1, 0))
48
49     def testRange(self):
50         self.assertInvalid((1, 3))
51         self.assertValid((1, 5))
52         self.assertValid((1, 8))
53         self.assertInvalid((1, 9))
54
55     def testFilesField(self):
56         self.assertInvalid((1, 7), field='notfiles')
57         self.assertValid((1, 8), field='notfiles')
58
59 if __name__ == '__main__':
60     unittest.main()