[pitivi] Fix pylint abstract-method



commit 6eae34e921b0298a2c0661702c18d58b6bf59c46
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Oct 29 10:33:00 2019 +0100

    Fix pylint abstract-method

 pitivi/check.py         | 82 +++++++++++++++++++++++++++----------------------
 pitivi/undo/timeline.py |  3 ++
 pitivi/undo/undo.py     |  2 ++
 pre-commit.hook         |  2 --
 tests/test_check.py     | 34 ++++++++++----------
 5 files changed, 67 insertions(+), 56 deletions(-)
---
diff --git a/pitivi/check.py b/pitivi/check.py
index 566b2f05..bc7a4caa 100644
--- a/pitivi/check.py
+++ b/pitivi/check.py
@@ -44,14 +44,14 @@ class Dependency:
 
     Args:
         modulename (str): The name identifying the component.
-        version_required_string (Optional[str]): The minimum required version,
+        version_required (Optional[str]): The minimum required version,
             if any, formatted like "X.Y.Z".
         additional_message (Optional[str]): Message displayed to the user to
             further explain the purpose of the missing component.
     """
 
-    def __init__(self, modulename, version_required_string=None, additional_message=None):
-        self.version_required_string = version_required_string
+    def __init__(self, modulename, version_required=None, additional_message=None):
+        self.version_required = version_required
         self.modulename = modulename
         self.satisfied = False
         self.version_installed = None
@@ -67,14 +67,15 @@ class Dependency:
 
         if not self.component:
             self.satisfied = False
-        elif self.version_required_string is None:
-            self.satisfied = True
         else:
-            formatted_version = self._format_version(self.component)
-            self.version_installed = _version_to_string(formatted_version)
-
-            if formatted_version >= _string_to_list(self.version_required_string):
+            if self.version_required is None:
                 self.satisfied = True
+            else:
+                formatted_version = self._format_version(self.component)
+                self.version_installed = _version_to_string(formatted_version)
+
+                if formatted_version >= _string_to_list(self.version_required):
+                    self.satisfied = True
 
     def _try_importing_component(self):
         """Performs the check.
@@ -110,7 +111,7 @@ class Dependency:
         else:
             # Translators: %s is a Python module name or another os component
             message = _("- %s version %s is installed but Pitivi requires at least version %s") % (
-                self.modulename, self.version_installed, self.version_required_string)
+                self.modulename, self.version_installed, self.version_required)
 
         if self.additional_message is not None:
             message += "\n    -> " + self.additional_message
@@ -119,10 +120,11 @@ class Dependency:
 
 
 class GIDependency(Dependency):
+    # pylint: disable=abstract-method
 
-    def __init__(self, modulename, apiversion, version_required_string=None, additional_message=None):
+    def __init__(self, modulename, apiversion, version_required=None, additional_message=None):
         self.__api_version = apiversion
-        Dependency.__init__(self, modulename, version_required_string, additional_message)
+        Dependency.__init__(self, modulename, version_required, additional_message)
 
     def _try_importing_component(self):
         try:
@@ -140,6 +142,7 @@ class GIDependency(Dependency):
 
 
 class ClassicDependency(Dependency):
+    # pylint: disable=abstract-method
 
     def _try_importing_component(self):
         try:
@@ -186,7 +189,7 @@ class GstPluginDependency(Dependency):
         else:
             # Translators: %s is a Python module name or another os component
             message = _("- %s Gstreamer plug-in version %s is installed but Pitivi requires at least version 
%s") % (
-                self.modulename, self.version_installed, self.version_required_string)
+                self.modulename, self.version_installed, self.version_required)
 
         if self.additional_message is not None:
             message += "\n    -> " + self.additional_message
@@ -208,8 +211,8 @@ class GtkDependency(GIDependency):
 
 class CairoDependency(ClassicDependency):
 
-    def __init__(self, version_required_string):
-        ClassicDependency.__init__(self, "cairo", version_required_string)
+    def __init__(self, version_required):
+        ClassicDependency.__init__(self, "cairo", version_required)
 
     def _format_version(self, module):
         return _string_to_list(module.cairo_version_string())
@@ -276,8 +279,9 @@ def _check_gst_python():
 
 
 class GICheck(ClassicDependency):
-    def __init__(self, version_required_string):
-        ClassicDependency.__init__(self, "gi", version_required_string)
+
+    def __init__(self, version_required):
+        ClassicDependency.__init__(self, "gi", version_required)
 
     def _format_version(self, module):
         return list(module.version_info)
@@ -422,29 +426,35 @@ GST_API_VERSION = "1.0"
 GST_VERSION = "1.14.1"
 GTK_API_VERSION = "3.0"
 GLIB_API_VERSION = "2.0"
-HARD_DEPENDENCIES = [GICheck("3.20.0"),
-                     CairoDependency("1.10.0"),
-                     GstDependency("Gst", GST_API_VERSION, GST_VERSION),
-                     GstDependency("GES", GST_API_VERSION, GST_VERSION),
-                     GIDependency("GstTranscoder", GST_API_VERSION),
-                     GIDependency("GstVideo", GST_API_VERSION),
-                     GtkDependency("Gtk", GTK_API_VERSION, "3.20.0"),
+HARD_DEPENDENCIES = [GICheck(version_required="3.20.0"),
+                     CairoDependency(version_required="1.10.0"),
+                     GstDependency("Gst",
+                                   apiversion=GST_API_VERSION,
+                                   version_required=GST_VERSION),
+                     GstDependency("GES",
+                                   apiversion=GST_API_VERSION,
+                                   version_required=GST_VERSION),
+                     GIDependency("GstTranscoder", apiversion=GST_API_VERSION),
+                     GIDependency("GstVideo", apiversion=GST_API_VERSION),
+                     GtkDependency("Gtk",
+                                   apiversion=GTK_API_VERSION,
+                                   version_required="3.20.0"),
                      ClassicDependency("numpy"),
-                     GIDependency("Gio", "2.0"),
+                     GIDependency("Gio", apiversion="2.0"),
                      GstPluginDependency("gtk"),
                      GstPluginDependency("gdkpixbuf"),
                      ClassicDependency("matplotlib"),
-                     GIDependency("Peas", "1.0"),
+                     GIDependency("Peas", apiversion="1.0"),
                      ]
 
 SOFT_DEPENDENCIES = (
-    GIDependency("GSound", "1.0", None,
-                 _("enables sound notifications when rendering is complete")),
-    GIDependency("Notify", "0.7", None,
-                 _("enables visual notifications when rendering is complete")),
-    GstPluginDependency("libav", None,
-                        _("additional multimedia codecs through the GStreamer Libav library")),
-    GstPluginDependency("debugutilsbad", None,
-                        _("enables a watchdog in the GStreamer pipeline."
-                          " Use to detect errors happening in GStreamer"
-                          " and recover from them")))
+    GIDependency("GSound", apiversion="1.0", version_required=None,
+                 additional_message=_("enables sound notifications when rendering is complete")),
+    GIDependency("Notify", apiversion="0.7", version_required=None,
+                 additional_message=_("enables visual notifications when rendering is complete")),
+    GstPluginDependency("libav", version_required=None,
+                        additional_message=_("additional multimedia codecs through the GStreamer Libav 
library")),
+    GstPluginDependency("debugutilsbad", version_required=None,
+                        additional_message=_("enables a watchdog in the GStreamer pipeline."
+                                             " Use to detect errors happening in GStreamer"
+                                             " and recover from them")))
diff --git a/pitivi/undo/timeline.py b/pitivi/undo/timeline.py
index 5951ab41..ff13ee20 100644
--- a/pitivi/undo/timeline.py
+++ b/pitivi/undo/timeline.py
@@ -155,6 +155,7 @@ class TrackElementObserver(TimelineElementObserver):
 
 
 class TrackElementAction(UndoableAction):
+    # pylint: disable=abstract-method
 
     def __init__(self, clip, track_element):
         UndoableAction.__init__(self)
@@ -276,6 +277,7 @@ class ControlSourceObserver(GObject.Object):
 
 
 class ClipAction(UndoableAction):
+    # pylint: disable=abstract-method
 
     def __init__(self, layer, clip):
         UndoableAction.__init__(self)
@@ -368,6 +370,7 @@ class ClipRemoved(ClipAction):
 
 
 class TransitionClipAction(UndoableAction):
+    # pylint: disable=abstract-method
 
     def __init__(self, ges_layer, ges_clip, track_element):
         UndoableAction.__init__(self)
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index 5a5d1c91..4d77411d 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -80,6 +80,8 @@ class UndoableAutomaticObjectAction(UndoableAction):
             and might become obsolete later.
     """
 
+    # pylint: disable=abstract-method
+
     __updates = {}
 
     def __init__(self, auto_object):
diff --git a/pre-commit.hook b/pre-commit.hook
index 95a6c033..4ed16d41 100755
--- a/pre-commit.hook
+++ b/pre-commit.hook
@@ -15,7 +15,6 @@ PYLINT_IGNORED_FILES="
 bin/pitivi.in
 pitivi/application.py
 pitivi/autoaligner.py
-pitivi/check.py
 pitivi/dialogs/clipmediaprops.py
 pitivi/dialogs/prefs.py
 pitivi/editorperspective.py
@@ -48,7 +47,6 @@ pitivi/viewer/overlay_stack.py
 pitivi/viewer/title_overlay.py
 pitivi/viewer/viewer.py
 tests/common.py
-tests/test_check.py
 tests/test_log.py
 tests/test_medialibrary.py
 tests/test_preset.py
diff --git a/tests/test_check.py b/tests/test_check.py
index cdc11852..315862a5 100644
--- a/tests/test_check.py
+++ b/tests/test_check.py
@@ -16,30 +16,28 @@
 # License along with this program; if not, write to the
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
-from pitivi import check
-from tests import common
-
+from unittest import mock
 
-class FakeDependency(check.Dependency):
-    import_result = None
-
-    def _try_importing_component(self):
-        return self.import_result
+from pitivi.check import Dependency
+from tests import common
 
 
 class TestDependency(common.TestCase):
 
     def testBoolEvaluation(self):
-        dependency = FakeDependency(
-            modulename="module1", version_required_string=None)
-        self.assertFalse(dependency)
-        self.assertFalse(dependency.satisfied)
-
-        dependency.check()
+        dependency = Dependency(
+            modulename="module1", version_required=None)
         self.assertFalse(dependency)
         self.assertFalse(dependency.satisfied)
 
-        dependency.import_result = "something"
-        dependency.check()
-        self.assertTrue(dependency)
-        self.assertTrue(dependency.satisfied)
+        with mock.patch.object(dependency, "_try_importing_component") as func:
+            func.return_value = None
+            dependency.check()
+            self.assertFalse(dependency)
+            self.assertFalse(dependency.satisfied)
+
+        with mock.patch.object(dependency, "_try_importing_component") as func:
+            func.return_value = "something"
+            dependency.check()
+            self.assertTrue(dependency)
+            self.assertTrue(dependency.satisfied)


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