[pitivi] Fix use of `assert` followed by an expression



commit c08333e94e3d19c9638f50af4b29ad32675807a3
Author: ymdatta <ymdatta protonmail com>
Date:   Tue Mar 12 11:28:01 2019 +0530

    Fix use of `assert` followed by an expression
    
    Fixes #2284

 pitivi/effects.py                     |  3 ++-
 pitivi/project.py                     |  5 +++--
 pitivi/render.py                      |  2 +-
 pitivi/timeline/elements.py           |  6 ++++--
 pitivi/titleeditor.py                 | 18 +++++++++++-------
 pitivi/undo/timeline.py               | 11 +++++++----
 pitivi/utils/custom_effect_widgets.py | 14 ++++++++------
 7 files changed, 36 insertions(+), 23 deletions(-)
---
diff --git a/pitivi/effects.py b/pitivi/effects.py
index 9e8c07f6..c80eeb44 100644
--- a/pitivi/effects.py
+++ b/pitivi/effects.py
@@ -290,7 +290,8 @@ class EffectsManager(Loggable):
             bus = pipeline.get_bus()
             bus.add_signal_watch()
             bus.connect("message", self._gl_pipeline_message_cb, pipeline)
-            assert pipeline.set_state(Gst.State.PAUSED) == Gst.StateChangeReturn.ASYNC
+            res = pipeline.set_state(Gst.State.PAUSED)
+            assert res == Gst.StateChangeReturn.ASYNC
 
     def _gl_pipeline_message_cb(self, bus, message, pipeline):
         """Handles a `message` event on the pipeline for checking gl effects."""
diff --git a/pitivi/project.py b/pitivi/project.py
index bb8616fa..3641b5f3 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -1504,7 +1504,8 @@ class Project(Loggable, GES.Project):
 
                 for prop, value in settings.items():
                     encoder.set_property(prop, value)
-                assert encoder.save_preset(preset)
+                res = encoder.save_preset(preset)
+                assert res
 
         return GES.Project.save(self, ges_timeline, uri, formatter_asset, overwrite)
 
@@ -1813,7 +1814,7 @@ class Project(Loggable, GES.Project):
                                                       ref_restrictions,
                                                       defaults,
                                                       prev_vals)
-        assert(restriction)
+        assert restriction
         preset_name = encoder.get_factory().get_name()
         profile.set_restriction(restriction)
         profile.set_preset_name(preset_name)
diff --git a/pitivi/render.py b/pitivi/render.py
index b4498ae0..4c7d4f15 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -1025,7 +1025,7 @@ class RenderDialog(Loggable):
 
     # -- UI callbacks
     def _okButtonClickedCb(self, unused_button, media_type):
-        assert(media_type in ("audio", "video"))
+        assert media_type in ("audio", "video")
         setattr(self.project, media_type[0] + 'codecsettings', self.dialog.getSettings())
 
         caps = self.dialog.get_caps()
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index 618be692..47026eca 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -708,8 +708,10 @@ class TimelineElement(Gtk.Layout, Zoomable, Loggable):
                 (self.__controlledProperty.maximum -
                  self.__controlledProperty.minimum)
             inpoint = self._ges_elem.props.in_point
-            assert source.set(inpoint, val)
-            assert source.set(inpoint + self._ges_elem.props.duration, val)
+            res = source.set(inpoint, val)
+            assert res
+            res = source.set(inpoint + self._ges_elem.props.duration, val)
+            assert res
 
     def __create_keyframe_curve(self, bindings=[]):
         """Creates required keyframe curve."""
diff --git a/pitivi/titleeditor.py b/pitivi/titleeditor.py
index 66ef9b11..c8f9381e 100644
--- a/pitivi/titleeditor.py
+++ b/pitivi/titleeditor.py
@@ -120,7 +120,8 @@ class TitleEditor(Loggable):
                                          toplevel=True):
             self._setting_props = True
             try:
-                assert self.source.set_child_property(name, value)
+                res = self.source.set_child_property(name, value)
+                assert res
             finally:
                 self._setting_props = False
 
@@ -228,12 +229,15 @@ class TitleEditor(Loggable):
         # Now that the clip is inserted in the timeline, it has a source which
         # can be used to set its properties.
         source = title_clip.get_children(False)[0]
-        assert source.set_child_property("text", "")
-        assert source.set_child_property("foreground-color", BACKGROUND_DEFAULT_COLOR)
-        assert source.set_child_property("color", FOREGROUND_DEFAULT_COLOR)
-        assert source.set_child_property("font-desc", DEFAULT_FONT_DESCRIPTION)
-        assert source.set_child_property("valignment", DEFAULT_VALIGNMENT)
-        assert source.set_child_property("halignment", DEFAULT_HALIGNMENT)
+        properties = {"text": "",
+                      "foreground-color": BACKGROUND_DEFAULT_COLOR,
+                      "color": FOREGROUND_DEFAULT_COLOR,
+                      "font-desc": DEFAULT_FONT_DESCRIPTION,
+                      "valignment": DEFAULT_VALIGNMENT,
+                      "halignment": DEFAULT_HALIGNMENT}
+        for prop, value in properties.items():
+            res = source.set_child_property(prop, value)
+            assert res
         # Select it so the Title editor becomes active.
         self._selection.setSelection([title_clip], SELECT)
         self.app.gui.editor.timeline_ui.timeline.resetSelectionGroup()
diff --git a/pitivi/undo/timeline.py b/pitivi/undo/timeline.py
index 58ff29e2..67d139fc 100644
--- a/pitivi/undo/timeline.py
+++ b/pitivi/undo/timeline.py
@@ -174,7 +174,8 @@ class TrackElementAction(UndoableAction):
             self.track_element_props.append((prop_name, value))
 
     def add(self):
-        assert self.clip.add(self.track_element)
+        res = self.clip.add(self.track_element)
+        assert res
         for prop_name, prop_value in self.track_element_props:
             self.track_element.set_child_property(prop_name, prop_value)
 
@@ -297,7 +298,7 @@ class ClipAction(UndoableAction):
         self.clip.connect("child-added", child_added_cb)
         try:
             res = self.layer.add_clip(self.clip)
-            assert(res)
+            assert res
         finally:
             self.clip.disconnect_by_func(child_added_cb)
 
@@ -612,7 +613,8 @@ class ControlSourceSetAction(UndoableAction):
                                               self.property_name, self.binding_type)
 
     def undo(self):
-        assert self.track_element.remove_control_binding(self.property_name)
+        res = self.track_element.remove_control_binding(self.property_name)
+        assert res
 
     def asScenarioAction(self):
         st = Gst.Structure.new_empty("set-control-source")
@@ -634,7 +636,8 @@ class ControlSourceRemoveAction(UndoableAction):
         self.binding_type = "direct-absolute" if binding.props.absolute else "direct"
 
     def do(self):
-        assert self.track_element.remove_control_binding(self.property_name)
+        res = self.track_element.remove_control_binding(self.property_name)
+        assert res
 
     def undo(self):
         self.track_element.set_control_source(self.control_source,
diff --git a/pitivi/utils/custom_effect_widgets.py b/pitivi/utils/custom_effect_widgets.py
index 7a8286a2..b599b024 100644
--- a/pitivi/utils/custom_effect_widgets.py
+++ b/pitivi/utils/custom_effect_widgets.py
@@ -54,8 +54,9 @@ def create_custom_prop_widget_cb(unused_effect_prop_manager, effect_widget, effe
     effect_name = effect.get_property("bin-description")
     if effect_name == "alpha":
         return create_custom_alpha_prop_widget(effect_widget, effect, prop, prop_value)
-    elif effect_name == "frei0r-filter-alphaspot":
+    if effect_name == "frei0r-filter-alphaspot":
         return create_custom_alphaspot_prop_widget(effect_widget, effect, prop, prop_value)
+    return None
 
 
 def create_custom_widget_cb(effect_prop_manager, effect_widget, effect):
@@ -67,17 +68,18 @@ def create_custom_widget_cb(effect_prop_manager, effect_widget, effect):
     if effect_name == "alpha":
         widget = create_alpha_widget(effect_prop_manager, effect_widget, effect)
         return widget
-    elif effect_name == "frei0r-filter-3-point-color-balance":
+    if effect_name == "frei0r-filter-3-point-color-balance":
         widget = create_3point_color_balance_widget(effect_prop_manager, effect_widget, effect)
         return widget
-    elif effect_name == "frei0r-filter-alphaspot":
+    if effect_name == "frei0r-filter-alphaspot":
         widget = create_alphaspot_widget(effect_prop_manager, effect_widget, effect)
         return widget
 
     # Check if there is a UI file available as a glade file
-    # Assuming a GtkGrid called base_table exists
     if not os.path.isfile(path):
         return None
+
+    # Assuming a GtkGrid called base_table exists
     builder = setup_from_ui_file(effect_widget, path)
     widget = builder.get_object("base_table")
     return widget
@@ -373,7 +375,7 @@ def create_alphaspot_widget(effect_prop_manager, element_setting_widget, element
         for index, vals in reversed(list(enumerate(shape_list))):
             if flid >= vals[1]:
                 return index
-        assert False
+        raise Exception()
 
     shape_picker.set_active(get_current_shape())
 
@@ -414,7 +416,7 @@ def create_alphaspot_widget(effect_prop_manager, element_setting_widget, element
         for index, vals in reversed(list(enumerate(op_list))):
             if flid >= vals[1]:
                 return index
-        assert False
+        raise Exception()
 
     op_picker.set_active(get_current_op())
 


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