X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tests%2Ftest_srcformats.py;h=4ecaf8b7fcc83925238f2473ed7961714158eee2;hb=7e1fd15629858d8b3437cb7626f853e74c461ec1;hp=9fec4a8765fd0db46d86fc636feee6773dcce542;hpb=28f3e6f0659504214d482d682f4b2b4791872cc6;p=dak.git diff --git a/tests/test_srcformats.py b/tests/test_srcformats.py index 9fec4a87..4ecaf8b7 100755 --- a/tests/test_srcformats.py +++ b/tests/test_srcformats.py @@ -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,27 @@ class FormatTreeQuiltTestCase(SourceFormatTestCase): 'native_tar': 1, }) +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()