]> git.decadent.org.uk Git - dak.git/blob - tests/test_srcformats.py
Cope with missing suite
[dak.git] / tests / test_srcformats.py
1 #!/usr/bin/env python
2
3 from base_test import DakTestCase
4
5 from daklib import srcformats
6 from collections import defaultdict
7 from daklib.formats import parse_format
8 from daklib.dak_exceptions import UnknownFormatError
9
10 class SourceFormatTestCase(DakTestCase):
11     def get_rejects(self, has_vars):
12         has = defaultdict(lambda: 0)
13         has.update(has_vars)
14         return list(self.fmt.reject_msgs(has))
15
16     def assertAccepted(self, has):
17         self.assertEqual(self.get_rejects(has), [])
18
19     def assertRejected(self, has):
20         self.assertNotEqual(self.get_rejects(has), [])
21
22 class FormatOneTestCase(SourceFormatTestCase):
23     fmt = srcformats.FormatOne
24
25     def testEmpty(self):
26         self.assertRejected({})
27
28     def testNative(self):
29         self.assertAccepted({'native_tar': 1, 'native_tar_gz': 1})
30
31     def testStandard(self):
32         self.assertAccepted({
33             'orig_tar': 1,
34             'orig_tar_gz': 1,
35             'debian_diff': 1,
36         })
37
38     def testDisallowed(self):
39         self.assertRejected({
40             'native_tar': 1,
41             'native_tar_gz': 1,
42             'debian_tar': 1,
43         })
44         self.assertRejected({
45             'orig_tar': 1,
46             'orig_tar_gz': 1,
47             'debian_diff': 0,
48         })
49         self.assertRejected({
50             'native_tar': 1,
51             'native_tar_gz': 1,
52             'more_orig_tar': 1,
53         })
54         self.assertRejected({
55             'native_tar': 1,
56             'native_tar_gz': 1,
57             'debian_diff': 1,
58         })
59
60 class FormatTreeTestCase(SourceFormatTestCase):
61     fmt = srcformats.FormatThree
62
63     def testEmpty(self):
64         self.assertRejected({})
65
66     def testSimple(self):
67         self.assertAccepted({'native_tar': 1})
68
69     def testDisallowed(self):
70         self.assertRejected({'native_tar': 1, 'orig_tar': 1})
71         self.assertRejected({'native_tar': 1, 'debian_diff': 1})
72         self.assertRejected({'native_tar': 1, 'debian_tar': 1})
73         self.assertRejected({'native_tar': 1, 'more_orig_tar': 1})
74
75 class FormatTreeQuiltTestCase(SourceFormatTestCase):
76     fmt = srcformats.FormatThreeQuilt
77
78     def testEmpty(self):
79         self.assertRejected({})
80
81     def testSimple(self):
82         self.assertAccepted({'orig_tar': 1, 'debian_tar': 1})
83
84     def testMultipleTarballs(self):
85         self.assertAccepted({
86             'orig_tar': 1,
87             'debian_tar': 1,
88             'more_orig_tar': 42,
89         })
90
91     def testDisallowed(self):
92         self.assertRejected({
93             'orig_tar': 1,
94             'debian_tar': 1,
95             'debian_diff': 1
96         })
97         self.assertRejected({
98             'orig_tar': 1,
99             'debian_tar': 1,
100             'native_tar': 1,
101         })
102
103 class FormatFromStringTestCase(DakTestCase):
104     def assertFormat(self, txt, klass):
105         self.assertEqual(srcformats.get_format_from_string(txt), klass)
106
107     def assertInvalid(self, txt):
108         self.assertRaises(
109             UnknownFormatError,
110             lambda: srcformats.get_format_from_string(txt),
111         )
112
113     def testFormats(self):
114         self.assertFormat('1.0', srcformats.FormatOne)
115         self.assertFormat('3.0 (native)', srcformats.FormatThree)
116         self.assertFormat('3.0 (quilt)', srcformats.FormatThreeQuilt)
117
118     def testInvalidFormats(self):
119         self.assertInvalid('')
120         self.assertInvalid('.')
121         self.assertInvalid('3.0 (cvs)')
122         self.assertInvalid(' 1.0 ')
123         self.assertInvalid('8.4 (hardy)')
124
125 if __name__ == '__main__':
126     unittest.main()