X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tests%2Ftest_srcformats.py;h=42ff63898059b0c5c76b771281f0ecf7aa2fb13f;hb=7c5adcf962fe99d6a42307595f263f47d0112fbc;hp=9fec4a8765fd0db46d86fc636feee6773dcce542;hpb=68ef7be81d7e958d0147d92ee5f6919746448377;p=dak.git diff --git a/tests/test_srcformats.py b/tests/test_srcformats.py index 9fec4a87..42ff6389 100755 --- a/tests/test_srcformats.py +++ b/tests/test_srcformats.py @@ -1,15 +1,13 @@ #!/usr/bin/env python -import unittest - -import os, sys -sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - -from collections import defaultdict +from base_test import DakTestCase from daklib import srcformats +from collections import defaultdict +from daklib.formats import parse_format +from daklib.dak_exceptions import UnknownFormatError -class SourceFormatTestCase(unittest.TestCase): +class SourceFormatTestCase(DakTestCase): def get_rejects(self, has_vars): has = defaultdict(lambda: 0) has.update(has_vars) @@ -58,6 +56,12 @@ class FormatOneTestCase(SourceFormatTestCase): 'native_tar_gz': 1, 'debian_diff': 1, }) + self.assertRejected({ + 'orig_tar': 1, + 'orig_tar_gz': 1, + 'debian_diff': 1, + 'orig_tar_sig': 1, + }) class FormatTreeTestCase(SourceFormatTestCase): fmt = srcformats.FormatThree @@ -102,5 +106,28 @@ class FormatTreeQuiltTestCase(SourceFormatTestCase): 'native_tar': 1, }) +class FormatFromStringTestCase(DakTestCase): + 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__': + import unittest unittest.main()