]> git.decadent.org.uk Git - dak.git/commitdiff
Generate lintian reject messages in daklib.lintian + tests
authorChris Lamb <lamby@debian.org>
Sat, 31 Oct 2009 10:03:19 +0000 (10:03 +0000)
committerChris Lamb <lamby@debian.org>
Sat, 31 Oct 2009 23:00:12 +0000 (23:00 +0000)
Signed-off-by: Chris Lamb <lamby@debian.org>
daklib/lintian.py
daklib/queue.py
tests/test_lintian.py

index c0ee316a6e4a172e7690fd7a9991e73b04afe0ab..32c63db0d2e3199f41650b66444e6a2767a300ad 100644 (file)
@@ -12,3 +12,49 @@ def parse_lintian_output(output):
         m = re_parse_lintian.match(line)
         if m:
             yield m.groups()
+
+def generate_reject_messages(parsed_tags, tag_definitions, log=lambda *args: args):
+    rejects = []
+
+    tags = set()
+    for values in tag_definitions.values():
+        for tag in values:
+            tags.add(tag)
+
+    for etype, epackage, etag, etext in parsed_tags:
+        if etag not in tags:
+            continue
+
+        # Was tag overridden?
+        if etype == 'O':
+
+            if etag in tag_definitions['nonfatal']:
+                # Overriding this tag is allowed.
+                pass
+
+            elif etag in tag_definitions['fatal']:
+                # Overriding this tag is NOT allowed.
+
+                log('ftpmaster does not allow tag to be overridable', etag)
+                rejects.append(
+                    "%s: Overriden tag %s found, but this tag "
+                    "may not be overridden." % (epackage, etag)
+                )
+
+        else:
+            # Tag is known and not overridden; reject
+            rejects.append(
+                "%s: Found lintian output: '%s %s', automatically "
+                "rejected package." % (epackage, etag, etext)
+            )
+
+            # Now tell if they *might* override it.
+            if etag in tag_definitions['nonfatal']:
+                log("auto rejecting", "overridable", etag)
+                rejects.append(
+                    "%s: If you have a good reason, you may override this "
+                    "lintian tag." % epackage)
+            else:
+                log("auto rejecting", "not overridable", etag)
+
+    return rejects
index f52fe3638eab71f153634348a431d58b540711cf..bb66b2fd2840f5d7b9116d0c3418d8f7aa174b7b 100755 (executable)
@@ -54,7 +54,7 @@ from summarystats import SummaryStats
 from utils import parse_changes, check_dsc_files
 from textutils import fix_maintainer
 from binary import Binary
-from lintian import parse_lintian_output
+from lintian import parse_lintian_output, generate_reject_messages
 
 ###############################################################################
 
@@ -1287,14 +1287,11 @@ class Upload(object):
         # through lintians output later to see if its a fatal tag we detected, or not.
         # So we only run lintian once on all tags, even if we might reject on some, but not
         # reject on others.
-        # Additionally build up a set of tags
-        tags = set()
         (fd, temp_filename) = utils.temp_filename()
         temptagfile = os.fdopen(fd, 'w')
-        for tagtype in lintiantags:
-            for tag in lintiantags[tagtype]:
+        for tags in lintiantags.values():
+            for tag in tags:
                 temptagfile.write("%s\n" % tag)
-                tags.add(tag)
         temptagfile.close()
 
         # So now we should look at running lintian at the .changes file, capturing output
@@ -1311,35 +1308,15 @@ class Upload(object):
             utils.warn("lintian failed for %s [return code: %s]." % (self.pkg.changes_file, result))
             utils.warn(utils.prefix_multi_line_string(output, " [possible output:] "))
 
+        parsed_tags = parse_lintian_output(output)
+
         def log(*txt):
             if self.logger:
                 self.logger.log([self.pkg.changes_file, "check_lintian"] + list(txt))
 
-        for etype, epackage, etag, etext in parse_lintian_output(output):
-
-            # So lets check if we know the tag at all.
-            if etag not in tags:
-                continue
-
-            if etype == 'O':
-                # We know it and it is overriden. Check that override is allowed.
-                if etag in lintiantags['nonfatal']:
-                    # The tag is overriden, and it is allowed to be overriden.
-                    # Don't add a reject message.
-                    pass
-                elif etag in lintiantags['fatal']:
-                    # The tag is overriden - but is not allowed to be
-                    self.rejects.append("%s: Overriden tag %s found, but this tag may not be overwritten." % (epackage, etag))
-                    log("ftpmaster does not allow tag to be overridable", etag)
-            else:
-                # Tag is known, it is not overriden, direct reject.
-                self.rejects.append("%s: Found lintian output: '%s %s', automatically rejected package." % (epackage, etag, etext))
-                # Now tell if they *might* override it.
-                if etag in lintiantags['nonfatal']:
-                    log("auto rejecting", "overridable", etag)
-                    self.rejects.append("%s: If you have a good reason, you may override this lintian tag." % (epackage))
-                else:
-                    log("auto rejecting", "not overridable", etag)
+        self.rejects.extend(
+            generate_reject_messages(parsed_tags, lintiantags, log=log)
+        )
 
     ###########################################################################
     def check_urgency(self):
index 99d5e93ab33d3653a20257faeeec9778b4aeceda..27d13680bf8855bae44b0e9a11e09ddafb334b71 100755 (executable)
@@ -4,7 +4,7 @@ from base_test import DakTestCase
 
 import unittest
 
-from daklib.lintian import parse_lintian_output
+from daklib.lintian import parse_lintian_output, generate_reject_messages
 
 class ParseLintianTestCase(DakTestCase):
     def assertParse(self, output, expected):
@@ -41,5 +41,58 @@ class ParseLintianTestCase(DakTestCase):
             [('W', 'pkgname source', 'some-tag', 'path/to/file')]
         )
 
+class GenerateRejectMessages(DakTestCase):
+    def assertNumReject(self, input, defs, num):
+        self.assertEqual(len(generate_reject_messages(input, defs)), num)
+
+    def testUnknownTag(self):
+        self.assertNumReject(
+            [('W', 'pkgname', 'unknown-tag', '')],
+            {'fatal': ['known-tag'], 'nonfatal': []},
+            0,
+        )
+
+    def testFatalTags(self):
+        self.assertNumReject([
+                ('W', 'pkgname', 'fatal-tag-1', ''),
+                ('W', 'pkgname', 'fatal-tag-2', ''),
+            ],
+            {'fatal': ['fatal-tag-1', 'fatal-tag-2'], 'nonfatal': []},
+            2,
+        )
+
+    def testMixture(self):
+        self.assertNumReject([
+                ('W', 'pkgname', 'fatal-tag', ''),
+                ('W', 'pkgname', 'unknown-tag', ''),
+            ],
+            {'fatal': ['fatal-tag'], 'nonfatal': []},
+            1,
+        )
+
+    def testOverridable(self):
+        self.assertNumReject([
+                ('W', 'pkgname', 'non-fatal-tag', ''),
+            ],
+            {'fatal': [], 'nonfatal': ['non-fatal-tag']},
+            1 + 1, # We add an extra 'reject' hint message
+        )
+
+    def testOverrideAllowed(self):
+        self.assertNumReject([
+                ('O', 'pkgname', 'non-fatal-tag', ''),
+            ],
+            {'fatal': [], 'nonfatal': ['non-fatal-tag']},
+            0,
+        )
+
+    def testOverrideNotAllowed(self):
+        self.assertNumReject([
+                ('O', 'pkgname', 'fatal-tag', ''),
+            ],
+            {'fatal': ['fatal-tag'], 'nonfatal': []},
+            1,
+        )
+
 if __name__ == '__main__':
     unittest.main()