[gobject-introspection] message: simplify handling of error levels



commit 06a460b3487ad58cc941169481cce073e2a196cc
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sun Jan 6 18:20:49 2019 +0100

    message: simplify handling of error levels
    
    Instead of allowing each error level to be enabled just enable all of them
    through the enable_warnings() method. This matches what the code is currently
    doing (minus that one helper script) and simplifies things.
    
    Also remove the error count, it's not used.

 giscanner/message.py                          | 13 ++++---------
 giscanner/scannermain.py                      |  2 +-
 misc/update-gtkdoc-tests.py                   |  2 +-
 tests/scanner/annotationparser/test_parser.py |  4 ++--
 tests/scanner/test_transformer.py             | 12 ++++++------
 tests/warn/warningtester.py                   |  4 ++--
 6 files changed, 16 insertions(+), 21 deletions(-)
---
diff --git a/giscanner/message.py b/giscanner/message.py
index 5e26592d..c59d133f 100644
--- a/giscanner/message.py
+++ b/giscanner/message.py
@@ -95,9 +95,8 @@ class MessageLogger(object):
         self._cwd = os.getcwd()
         self._output = output
         self._namespace = namespace
-        self._enable_warnings = []
+        self._enable_warnings = False
         self._warning_count = 0
-        self._error_count = 0
 
     @classmethod
     def get(cls, *args, **kwargs):
@@ -105,15 +104,12 @@ class MessageLogger(object):
             cls._instance = cls(*args, **kwargs)
         return cls._instance
 
-    def enable_warnings(self, log_types):
-        self._enable_warnings = log_types
+    def enable_warnings(self, value):
+        self._enable_warnings = bool(value)
 
     def get_warning_count(self):
         return self._warning_count
 
-    def get_error_count(self):
-        return self._error_count
-
     def log(self, log_type, text, positions=None, prefix=None, marker_pos=None, marker_line=None):
         """
         Log a warning, using optional file positioning information.
@@ -123,7 +119,7 @@ class MessageLogger(object):
 
         self._warning_count += 1
 
-        if log_type not in self._enable_warnings:
+        if not self._enable_warnings:
             return
 
         if type(positions) == set:
@@ -142,7 +138,6 @@ class MessageLogger(object):
             error_type = "Warning"
         elif log_type == ERROR:
             error_type = "Error"
-            self._error_count += 1
         elif log_type == FATAL:
             error_type = "Fatal"
 
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index 264bd517..c004fb19 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -550,7 +550,7 @@ def scanner_main(args):
     namespace = create_namespace(options)
     logger = message.MessageLogger.get(namespace=namespace)
     if options.warn_all:
-        logger.enable_warnings((message.WARNING, message.ERROR, message.FATAL))
+        logger.enable_warnings(True)
 
     transformer = create_transformer(namespace, options)
 
diff --git a/misc/update-gtkdoc-tests.py b/misc/update-gtkdoc-tests.py
index 566d6ac0..c182fc11 100644
--- a/misc/update-gtkdoc-tests.py
+++ b/misc/update-gtkdoc-tests.py
@@ -189,7 +189,7 @@ if __name__ == '__main__':
                 logger = MessageLogger.get(namespace=None)
                 parser = GtkDocCommentBlockParser()
                 writer = GtkDocCommentBlockWriter(indent=True)
-                logger.enable_warnings((ERROR, FATAL))
+                logger.enable_warnings(True)
 
                 with io.open(path, 'r') as f:
                     lines = f.readlines()
diff --git a/tests/scanner/annotationparser/test_parser.py b/tests/scanner/annotationparser/test_parser.py
index 368eb728..ee1103c2 100644
--- a/tests/scanner/annotationparser/test_parser.py
+++ b/tests/scanner/annotationparser/test_parser.py
@@ -33,7 +33,7 @@ import xml.etree.ElementTree as etree
 
 from giscanner.annotationparser import GtkDocCommentBlockParser, GtkDocCommentBlockWriter
 from giscanner.ast import Namespace
-from giscanner.message import MessageLogger, WARNING, ERROR, FATAL
+from giscanner.message import MessageLogger
 
 
 XML_NS = 'http://schemas.gnome.org/gobject-introspection/2013/test'
@@ -410,7 +410,7 @@ def create_test_cases():
     # Initialize message logger
     namespace = Namespace('Test', '1.0')
     logger = MessageLogger.get(namespace=namespace)
-    logger.enable_warnings((WARNING, ERROR, FATAL))
+    logger.enable_warnings(True)
     test_cases = {}
 
     # Load test cases from disc
diff --git a/tests/scanner/test_transformer.py b/tests/scanner/test_transformer.py
index 92f21c67..c6fbf4e7 100644
--- a/tests/scanner/test_transformer.py
+++ b/tests/scanner/test_transformer.py
@@ -10,7 +10,7 @@ os.environ['GI_SCANNER_DISABLE_CACHE'] = '1'
 from giscanner import ast
 from giscanner.sourcescanner import SourceScanner
 from giscanner.transformer import Transformer
-from giscanner.message import MessageLogger, WARNING, ERROR, FATAL
+from giscanner.message import MessageLogger
 
 
 def create_scanner_from_source_string(source):
@@ -85,7 +85,7 @@ class TestStructTypedefs(unittest.TestCase):
         # Hack to set logging singleton
         self.namespace = ast.Namespace('Test', '1.0')
         logger = MessageLogger.get(namespace=self.namespace)
-        logger.enable_warnings((WARNING, ERROR, FATAL))
+        logger.enable_warnings(True)
 
     def test_anonymous_typedef(self):
         load_namespace_from_source_string(self.namespace, """
@@ -280,7 +280,7 @@ class TestNestedStructs(unittest.TestCase):
         # Hack to set logging singleton
         self.namespace = ast.Namespace('Test', '1.0')
         logger = MessageLogger.get(namespace=self.namespace)
-        logger.enable_warnings((WARNING, ERROR, FATAL))
+        logger.enable_warnings(True)
 
     def test_nested_named(self):
         load_namespace_from_source_string(self.namespace, """
@@ -387,7 +387,7 @@ class TestUnions(unittest.TestCase):
         # Hack to set logging singleton
         self.namespace = ast.Namespace('Test', '1.0')
         logger = MessageLogger.get(namespace=self.namespace)
-        logger.enable_warnings((WARNING, ERROR, FATAL))
+        logger.enable_warnings(True)
 
     def test_union_with_struct(self):
         load_namespace_from_source_string(self.namespace, """
@@ -472,7 +472,7 @@ class TestCallbacks(unittest.TestCase):
         # Hack to set logging singleton
         self.namespace = ast.Namespace('Test', '1.0')
         logger = MessageLogger.get(namespace=self.namespace)
-        logger.enable_warnings((WARNING, ERROR, FATAL))
+        logger.enable_warnings(True)
 
     def test_union_with_struct(self):
         load_namespace_from_source_string(self.namespace, """
@@ -488,7 +488,7 @@ class TestArrays(unittest.TestCase):
         # Hack to set logging singleton
         self.namespace = ast.Namespace('Test', '1.0')
         logger = MessageLogger.get(namespace=self.namespace)
-        logger.enable_warnings((WARNING, ERROR, FATAL))
+        logger.enable_warnings(True)
 
     def test_multidimensional_arrays(self):
         """Multidimensional arrays are flattend into a single dimension."""
diff --git a/tests/warn/warningtester.py b/tests/warn/warningtester.py
index afc78ce0..fedd3a59 100644
--- a/tests/warn/warningtester.py
+++ b/tests/warn/warningtester.py
@@ -15,7 +15,7 @@ from giscanner.annotationparser import GtkDocCommentBlockParser
 from giscanner.ast import Include, Namespace
 from giscanner.introspectablepass import IntrospectablePass
 from giscanner.maintransformer import MainTransformer
-from giscanner.message import MessageLogger, WARNING, ERROR, FATAL
+from giscanner.message import MessageLogger
 from giscanner.sourcescanner import SourceScanner
 from giscanner.transformer import Transformer
 from giscanner.scannermain import process_packages
@@ -98,7 +98,7 @@ def check(args):
     output = ChunkedIO()
     namespace = Namespace('Test', '1.0')
     logger = MessageLogger.get(namespace=namespace, output=output)
-    logger.enable_warnings((WARNING, ERROR, FATAL))
+    logger.enable_warnings(True)
 
     transformer = Transformer(namespace)
     transformer.set_include_paths([


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]