X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tests%2Ftest_srcformats.py;h=9bc0ddf236dd064e434daa832ffcb05e17dda465;hb=ef55b8c79ae2d3e593aacb7a1f4a3c893bf62094;hp=d7b84496c86251b264aa93f7ee2c0201441fa743;hpb=fee8895dd909a9d0f4f4a71c83f689dabee62cfe;p=dak.git diff --git a/tests/test_srcformats.py b/tests/test_srcformats.py index d7b84496..9bc0ddf2 100755 --- a/tests/test_srcformats.py +++ b/tests/test_srcformats.py @@ -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.formats import parse_format from daklib.dak_exceptions import UnknownFormatError class SourceFormatTestCase(unittest.TestCase): @@ -105,28 +106,6 @@ class FormatTreeQuiltTestCase(SourceFormatTestCase): ## -class ParseFormatTestCase(unittest.TestCase): - def assertParse(self, format, expected): - self.assertEqual(srcformats.parse_format(format), expected) - - def assertParseFail(self, format): - self.assertRaises( - UnknownFormatError, - lambda: srcformats.parse_format(format) - ) - - def testParse(self): - self.assertParse('1.0', (1, 0)) - - def testEmpty(self): - self.assertParseFail('') - self.assertParseFail(' ') - self.assertParseFail(' ') - - def textText(self): - self.assertParse('1.2 (three)', (1, 2, 'three')) - self.assertParseFail('0.0 ()') - class ValidateFormatTestCase(unittest.TestCase): def assertValid(self, format, **kwargs): kwargs['is_a_dsc'] = kwargs.get('is_a_dsc', True) @@ -186,5 +165,27 @@ class ValidateFormatThreeQuiltTestCase(ValidateFormatTestCase): 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()