3 from base_test import DakTestCase
5 from daklib import srcformats
6 from collections import defaultdict
7 from daklib.formats import parse_format
8 from daklib.dak_exceptions import UnknownFormatError
10 class SourceFormatTestCase(DakTestCase):
11 def get_rejects(self, has_vars):
12 has = defaultdict(lambda: 0)
14 return list(self.fmt.reject_msgs(has))
16 def assertAccepted(self, has):
17 self.assertEqual(self.get_rejects(has), [])
19 def assertRejected(self, has):
20 self.assertNotEqual(self.get_rejects(has), [])
22 class FormatOneTestCase(SourceFormatTestCase):
23 fmt = srcformats.FormatOne
26 self.assertRejected({})
29 self.assertAccepted({'native_tar': 1, 'native_tar_gz': 1})
31 def testStandard(self):
38 def testDisallowed(self):
60 class FormatTreeTestCase(SourceFormatTestCase):
61 fmt = srcformats.FormatThree
64 self.assertRejected({})
67 self.assertAccepted({'native_tar': 1})
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})
75 class FormatTreeQuiltTestCase(SourceFormatTestCase):
76 fmt = srcformats.FormatThreeQuilt
79 self.assertRejected({})
82 self.assertAccepted({'orig_tar': 1, 'debian_tar': 1})
84 def testMultipleTarballs(self):
91 def testDisallowed(self):
103 class FormatFromStringTestCase(DakTestCase):
104 def assertFormat(self, txt, klass):
105 self.assertEqual(srcformats.get_format_from_string(txt), klass)
107 def assertInvalid(self, txt):
110 lambda: srcformats.get_format_from_string(txt),
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)
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)')
125 if __name__ == '__main__':