]> git.decadent.org.uk Git - dak.git/blobdiff - tests/test_srcformats.py
Move parse_format tests to test_formats.py
[dak.git] / tests / test_srcformats.py
index 9fec4a8765fd0db46d86fc636feee6773dcce542..9bc0ddf236dd064e434daa832ffcb05e17dda465 100755 (executable)
@@ -8,6 +8,8 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 from collections import defaultdict
 
 from daklib import srcformats
+from daklib.formats import parse_format
+from daklib.dak_exceptions import UnknownFormatError
 
 class SourceFormatTestCase(unittest.TestCase):
     def get_rejects(self, has_vars):
@@ -102,5 +104,88 @@ class FormatTreeQuiltTestCase(SourceFormatTestCase):
             'native_tar': 1,
         })
 
+##
+
+class ValidateFormatTestCase(unittest.TestCase):
+    def assertValid(self, format, **kwargs):
+        kwargs['is_a_dsc'] = kwargs.get('is_a_dsc', True)
+        self.fmt.validate_format(format, **kwargs)
+
+    def assertInvalid(self, *args, **kwargs):
+        self.assertRaises(
+            UnknownFormatError,
+            lambda: self.assertValid(*args, **kwargs),
+        )
+
+class ValidateFormatOneTestCase(ValidateFormatTestCase):
+    fmt = srcformats.FormatOne
+
+    def testValid(self):
+        self.assertValid((1, 0))
+
+    def testInvalid(self):
+        self.assertInvalid((0, 1))
+        self.assertInvalid((3, 0, 'quilt'))
+
+    ##
+
+    def testBinary(self):
+        self.assertValid((1, 5), is_a_dsc=False)
+        self.assertInvalid((1, 0), is_a_dsc=False)
+
+    def testRange(self):
+        self.assertInvalid((1, 3), is_a_dsc=False)
+        self.assertValid((1, 5), is_a_dsc=False)
+        self.assertValid((1, 8), is_a_dsc=False)
+        self.assertInvalid((1, 9), is_a_dsc=False)
+
+    def testFilesField(self):
+        self.assertInvalid((1, 7), is_a_dsc=False, field='notfiles')
+        self.assertValid((1, 8), is_a_dsc=False, field='notfiles')
+
+class ValidateFormatThreeTestCase(ValidateFormatTestCase):
+    fmt = srcformats.FormatThree
+
+    def testValid(self):
+        self.assertValid((3, 0, 'native'))
+
+    def testInvalid(self):
+        self.assertInvalid((1, 0))
+        self.assertInvalid((0, 0))
+        self.assertInvalid((3, 0, 'quilt'))
+
+class ValidateFormatThreeQuiltTestCase(ValidateFormatTestCase):
+    fmt = srcformats.FormatThreeQuilt
+
+    def testValid(self):
+        self.assertValid((3, 0, 'quilt'))
+
+    def testInvalid(self):
+        self.assertInvalid((1, 0))
+        self.assertInvalid((0, 0))
+        self.assertInvalid((3, 0, 'native'))
+
+class FormatFromStringTestCase(unittest.TestCase):
+    def assertFormat(self, txt, klass):
+        self.assertEqual(srcformats.get_format_from_string(txt), klass)
+
+    def assertInvalid(self, txt):
+        self.assertRaises(
+            UnknownFormatError,
+            lambda: srcformats.get_format_from_string(txt),
+        )
+
+    def testFormats(self):
+        self.assertFormat('1.0', srcformats.FormatOne)
+        self.assertFormat('3.0 (native)', srcformats.FormatThree)
+        self.assertFormat('3.0 (quilt)', srcformats.FormatThreeQuilt)
+
+    def testInvalidFormats(self):
+        self.assertInvalid('')
+        self.assertInvalid('.')
+        self.assertInvalid('3.0 (cvs)')
+        self.assertInvalid(' 1.0 ')
+        self.assertInvalid('8.4 (hardy)')
+
 if __name__ == '__main__':
     unittest.main()