]> git.decadent.org.uk Git - dak.git/commitdiff
Add regression tests for parse_format.
authorChris Lamb <lamby@debian.org>
Wed, 28 Oct 2009 11:05:34 +0000 (11:05 +0000)
committerChris Lamb <lamby@debian.org>
Wed, 28 Oct 2009 13:38:57 +0000 (13:38 +0000)
Signed-off-by: Chris Lamb <lamby@debian.org>
tests/test_srcformats.py

index 9fec4a8765fd0db46d86fc636feee6773dcce542..834a30b4fedf7c716b7fff9e90f9a96cde186d5d 100755 (executable)
@@ -8,6 +8,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 from collections import defaultdict
 
 from daklib import srcformats
+from daklib.dak_exceptions import UnknownFormatError
 
 class SourceFormatTestCase(unittest.TestCase):
     def get_rejects(self, has_vars):
@@ -102,5 +103,76 @@ class FormatTreeQuiltTestCase(SourceFormatTestCase):
             'native_tar': 1,
         })
 
+##
+
+class ParseFormat(unittest.TestCase):
+    def assertFormat(self, input, expected, **kwargs):
+        self.assertEqual(
+            srcformats.SourceFormat.parse_format(input, **kwargs),
+            expected,
+        )
+
+    def assertInvalidFormat(self, input, **kwargs):
+        self.assertRaises(
+            UnknownFormatError,
+            lambda: srcformats.SourceFormat.parse_format(input, **kwargs),
+        )
+
+    def testEmpty(self):
+        self.assertInvalidFormat('')
+        self.assertInvalidFormat(' ')
+        self.assertInvalidFormat('  ')
+
+    def testBroken(self):
+        self.assertInvalidFormat('.0')
+        self.assertInvalidFormat('.1')
+        self.assertInvalidFormat('format')
+
+class ParseSourceFormat(ParseFormat):
+    def assertFormat(self, *args, **kwargs):
+        kwargs['is_a_dsc'] = kwargs.get('is_a_dsc', True)
+        super(ParseSourceFormat, self).assertFormat(*args, **kwargs)
+
+    def assertInvalidFormat(self, *args, **kwargs):
+        kwargs['is_a_dsc'] = kwargs.get('is_a_dsc', True)
+        super(ParseSourceFormat, self).assertInvalidFormat(*args, **kwargs)
+
+    def testSimple(self):
+        self.assertFormat('1.0', (1, 0))
+
+    def testZero(self):
+        self.assertFormat('0.0', (0, 0))
+
+    def testNative(self):
+        self.assertFormat('3.0 (native)', (3, 0, 'native'))
+
+    def testQuilt(self):
+        self.assertFormat('3.0 (quilt)', (3, 0, 'quilt'))
+
+    def testUnknownThree(self):
+        self.assertInvalidFormat('3.0 (cvs)')
+
+class ParseBinaryFormat(ParseFormat):
+    def assertFormat(self, *args, **kwargs):
+        kwargs['is_a_dsc'] = kwargs.get('is_a_dsc', False)
+        super(ParseBinaryFormat, self).assertFormat(*args, **kwargs)
+
+    def assertInvalidFormat(self, *args, **kwargs):
+        kwargs['is_a_dsc'] = kwargs.get('is_a_dsc', False)
+        super(ParseBinaryFormat, self).assertInvalidFormat(*args, **kwargs)
+
+    def testSimple(self):
+        self.assertFormat('1.5', (1, 5))
+
+    def testRange(self):
+        self.assertInvalidFormat('1.0')
+        self.assertFormat('1.5', (1, 5))
+        self.assertFormat('1.8', (1, 8))
+        self.assertInvalidFormat('1.9')
+
+    def testFilesField(self):
+        self.assertInvalidFormat('1.7', field='notfiles')
+        self.assertFormat('1.8', (1, 8), field='notfiles')
+
 if __name__ == '__main__':
     unittest.main()