]> git.decadent.org.uk Git - dak.git/blobdiff - tests/test_parse_changes.py
dep11: Validate .xz compressed files as well
[dak.git] / tests / test_parse_changes.py
index 4f5ec72d0452ad92e4452c882b8f7eccecc5ccff..c7193dbef1148379509b097bd1f928ff09933965 100755 (executable)
@@ -4,6 +4,7 @@ from base_test import DakTestCase, fixture
 
 import unittest
 
+from daklib.gpg import GpgException
 from daklib.utils import parse_changes
 from daklib.dak_exceptions import InvalidDscError, ParseChangesError
 
@@ -11,55 +12,62 @@ class ParseChangesTestCase(DakTestCase):
     def assertParse(self, filename, *args):
         return parse_changes(fixture(filename), *args)
 
-    def assertFails(self, filename, line=None, *args):
-        try:
-            self.assertParse(filename, *args)
-            self.fail('%s was not recognised as invalid' % filename)
-        except ParseChangesError:
-            pass
-        except InvalidDscError, actual_line:
-            if line is not None:
-                assertEqual(actual_line, line)
-
 class ParseDscTestCase(ParseChangesTestCase):
     def test_1(self):
-        self.assertParse('dsc/1.dsc', 0, 1)
+        self.assertParse('dsc/1.dsc', -1, 1)
 
     def test_1_ignoreErrors(self):
         # Valid .dsc ; ignoring errors
-        self.assertParse('dsc/1.dsc', 0, 1)
+        self.assertParse('dsc/1.dsc', -1, 1)
 
     def test_2(self):
         # Missing blank line before signature body
-        self.assertParse('dsc/2.dsc', 0, 1)
+        self.assertParse('dsc/2.dsc', -1, 1)
 
     def test_2_ignoreErrors(self):
         # Invalid .dsc ; ignoring errors
-        self.assertParse('dsc/2.dsc', 0, 1)
+        self.assertParse('dsc/2.dsc', -1, 1)
 
     def test_3(self):
         # Missing blank line after signature header
-        self.assertParse('dsc/3.dsc', 0, 1)
+        self.assertParse('dsc/3.dsc', -1, 1)
 
     def test_4(self):
         # No blank lines at all
-        self.assertParse('dsc/4.dsc', 0, 1)
+        with self.assertRaises(GpgException):
+            self.assertParse('dsc/4.dsc', -1, 1)
 
     def test_5(self):
         # Extra blank line before signature body
-        self.assertParse('dsc/5.dsc', 0, 1)
+        self.assertParse('dsc/5.dsc', -1, 1)
 
     def test_6(self):
         # Extra blank line after signature header
-        self.assertParse('dsc/6.dsc', 0, 1)
+        self.assertParse('dsc/6.dsc', -1, 1)
+
+    def test_7(self):
+        # Blank file is an invalid armored GPG file
+        with self.assertRaises(GpgException):
+            self.assertParse('dsc/7.dsc', -1, 1)
+
+    def test_8(self):
+        # No armored contents
+        with self.assertRaisesRegexp(ParseChangesError, "Empty changes"):
+            self.assertParse('dsc/8.dsc', -1, 1)
+
+    def test_9(self):
+        changes = self.assertParse('dsc/9.dsc', -1, 1)
+        self.assert_(changes['question'] == 'Is this a bug?')
+        self.failIf(changes.get('this'))
 
 class ParseChangesTestCase(ParseChangesTestCase):
     def test_1(self):
         # Empty changes
-        self.assertFails('changes/1.changes', line=5)
+        with self.assertRaises(GpgException):
+            self.assertParse('changes/1.changes', 1)
 
     def test_2(self):
-        changes = self.assertParse('changes/2.changes', 0)
+        changes = self.assertParse('changes/2.changes', -1)
 
         binaries = changes['binary']
 
@@ -67,7 +75,7 @@ class ParseChangesTestCase(ParseChangesTestCase):
 
     def test_3(self):
         for filename in ('valid', 'bogus-pre', 'bogus-post'):
-            for strict_whitespace in (0, 1):
+            for strict_whitespace in (-1,):
                 changes = self.assertParse(
                     'changes/%s.changes' % filename,
                     strict_whitespace,