X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tests%2Ftest_srcformats.py;h=fa6f3b386c34aa3706d62b359f2755dc31ca70c1;hb=5f6b728e74c2eee87418250c3118c20b3b40a590;hp=0ae182313dcd82108289db099595dead1922a0b8;hpb=b7d36f712210b0efac983da88ae91cdd3fd7f469;p=dak.git diff --git a/tests/test_srcformats.py b/tests/test_srcformats.py index 0ae18231..fa6f3b38 100755 --- a/tests/test_srcformats.py +++ b/tests/test_srcformats.py @@ -1,16 +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) @@ -103,75 +100,27 @@ class FormatTreeQuiltTestCase(SourceFormatTestCase): 'native_tar': 1, }) -## - -class ParseFormatTestCase(unittest.TestCase): - def assertParse(self, format, expected): - self.assertEqual(srcformats.parse_format(format), expected) +class FormatFromStringTestCase(DakTestCase): + def assertFormat(self, txt, klass): + self.assertEqual(srcformats.get_format_from_string(txt), klass) - def assertParseFail(self, format): + def assertInvalid(self, txt): self.assertRaises( UnknownFormatError, - lambda: srcformats.parse_format(format) + lambda: srcformats.get_format_from_string(txt), ) - 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 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.assertInvalidFormat('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') + 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()