format = format[:2]
return format
+
+def validate_changes_format(format, field):
+ """
+ Validate a tuple-representation of a .changes Format: field. Raises
+ UnknownFormatError if the field is invalid, otherwise return type is
+ undefined.
+ """
+
+ if (format < (1, 5) or format > (1, 8)):
+ raise UnknownFormatError, repr(format)
+
+ if field != 'files' and format < (1, 8):
+ raise UnknownFormatError, repr(format)
import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-from daklib.formats import parse_format
+from daklib.formats import parse_format, validate_changes_format
from daklib.dak_exceptions import UnknownFormatError
class ParseFormatTestCase(unittest.TestCase):
def textText(self):
self.assertParse('1.2 (three)', (1, 2, 'three'))
self.assertParseFail('0.0 ()')
+
+class ValidateChangesFormat(unittest.TestCase):
+ def assertValid(self, changes, field='files'):
+ validate_changes_format(changes, field)
+
+ def assertInvalid(self, *args, **kwargs):
+ self.assertRaises(
+ UnknownFormatError,
+ lambda: self.assertValid(*args, **kwargs)
+ )
+
+ ##
+
+ def testBinary(self):
+ self.assertValid((1, 5))
+ self.assertValid((1, 8))
+ self.assertInvalid((1, 0))
+
+ def testRange(self):
+ self.assertInvalid((1, 3))
+ self.assertValid((1, 5))
+ self.assertValid((1, 8))
+ self.assertInvalid((1, 9))
+
+ def testFilesField(self):
+ self.assertInvalid((1, 7), field='notfiles')
+ self.assertValid((1, 8), field='notfiles')