[pitivi] tests_: Simplify create_pitivi_mock



commit 02b9766b99cc2c49a7869b423644e8bdfbec4af1
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Apr 19 23:10:09 2016 +0200

    tests_: Simplify create_pitivi_mock
    
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Differential Revision: https://phabricator.freedesktop.org/D924

 tests/common.py                 |   23 ++++++++---------------
 tests/test_mainwindow.py        |    7 +++----
 tests/test_media_library.py     |   17 +++++++----------
 tests/test_pipeline.py          |    2 +-
 tests/test_project.py           |    7 ++-----
 tests/test_timeline_timeline.py |    2 +-
 6 files changed, 22 insertions(+), 36 deletions(-)
---
diff --git a/tests/common.py b/tests/common.py
index 2bb2619..28a1bca 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -42,19 +42,21 @@ detect_leaks = os.environ.get("PITIVI_TEST_DETECT_LEAKS", "0") not in ("0", "")
 os.environ["PITIVI_USER_CACHE_DIR"] = tempfile.mkdtemp("pitiviTestsuite")
 
 
-def cleanPitiviMock(app):
+def clean_pitivi_mock(app):
     app.settings = None
     app.proxy_manager = None
 
 
-def getPitiviMock(settings=None, proxyingStrategy=ProxyingStrategy.NOTHING,
-                  numTranscodingJobs=4):
+def create_pitivi_mock(proxyingStrategy=ProxyingStrategy.NOTHING,
+                       numTranscodingJobs=4,
+                       **additional_settings):
+
     def __create_settings():
         settings = mock.MagicMock()
-
         settings.proxyingStrategy = proxyingStrategy
         settings.numTranscodingJobs = numTranscodingJobs
-
+        for key, value in additional_settings.items():
+            setattr(settings, key, value)
         return settings
 
     app = mock.MagicMock()
@@ -62,16 +64,7 @@ def getPitiviMock(settings=None, proxyingStrategy=ProxyingStrategy.NOTHING,
     app.write_action = mock.MagicMock(spec=Pitivi.write_action)
     check.check_requirements()
 
-    if not settings:
-        settings = __create_settings()
-    elif isinstance(settings, dict):
-        nsettings = __create_settings()
-
-        for key, value in settings.items():
-            setattr(nsettings, key, value)
-        settings = nsettings
-
-    app.settings = settings
+    app.settings = __create_settings()
     app.proxy_manager = ProxyManager(app)
 
     return app
diff --git a/tests/test_mainwindow.py b/tests/test_mainwindow.py
index 0ed1c6e..d377544 100644
--- a/tests/test_mainwindow.py
+++ b/tests/test_mainwindow.py
@@ -40,7 +40,7 @@ class TestMainWindow(common.TestCase):
         """
         Test tab switches
         """
-        app = common.getPitiviMock()
+        app = common.create_pitivi_mock()
         mainwindow = PitiviMainWindow(app)
         for expected_tab, b_element in [
                 (2, GES.TitleClip()),
@@ -60,9 +60,8 @@ class TestMainWindow(common.TestCase):
     def __loading_failure(self, has_proxy):
         mainloop = common.create_main_loop()
 
-        app = common.getPitiviMock(
-            settings={"lastProjectFolder": "/tmp",
-                      "edgeSnapDeadband": 32})
+        app = common.create_pitivi_mock(lastProjectFolder="/tmp",
+                                        edgeSnapDeadband=32)
         app.project_manager = ProjectManager(app)
         mainwindow = PitiviMainWindow(app)
         mainwindow.viewer = mock.MagicMock()
diff --git a/tests/test_media_library.py b/tests/test_media_library.py
index dd30eaa..0af7a43 100644
--- a/tests/test_media_library.py
+++ b/tests/test_media_library.py
@@ -49,20 +49,20 @@ class TestMediaLibrary(common.TestCase):
         self.mainloop = None
 
         if self.app:
-            self.app = common.cleanPitiviMock(self.app)
+            self.app = common.clean_pitivi_mock(self.app)
 
         if self.medialibrary:
             self.medialibrary.finalize()
             self.medialibrary = None
 
-    def _customSetUp(self, settings, project_uri=None):
+    def _customSetUp(self, project_uri=None, **kwargs):
         # Always make sure we start with a clean medialibrary, and no other
         # is connected to some assets.
         self.clean()
 
         self.mainloop = common.create_main_loop()
         self.check_no_transcoding = False
-        self.app = common.getPitiviMock(settings)
+        self.app = common.create_pitivi_mock(**kwargs)
         self.app.project_manager = ProjectManager(self.app)
         self.medialibrary = medialibrary.MediaLibraryWidget(self.app)
 
@@ -98,12 +98,9 @@ class TestMediaLibrary(common.TestCase):
 
     def runCheckImport(self, assets, proxying_strategy=ProxyingStrategy.ALL,
                        check_no_transcoding=False, clean_proxies=True):
-        settings = mock.MagicMock()
-        settings.proxyingStrategy = proxying_strategy
-        settings.numTranscodingJobs = 4
-        settings.lastClipView = medialibrary.SHOW_TREEVIEW
-
-        self._customSetUp(settings)
+        self._customSetUp(proxyingStrategy=proxying_strategy,
+                          numTranscodingJobs=4,
+                          lastClipView=medialibrary.SHOW_TREEVIEW)
         self.check_no_transcoding = check_no_transcoding
 
         self.medialibrary._progressbar.connect(
@@ -193,7 +190,7 @@ class TestMediaLibrary(common.TestCase):
         xges_path, uri = self.createTempProject()
 
         try:
-            self._customSetUp(None, project_uri=uri)
+            self._customSetUp(project_uri=uri)
             self.assertTrue(self.medialibrary._import_warning_infobar.props.visible)
         finally:
             os.remove(xges_path)
diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py
index e9090c1..71dbc4f 100644
--- a/tests/test_pipeline.py
+++ b/tests/test_pipeline.py
@@ -28,7 +28,7 @@ from tests import common
 class MockedPipeline(pipeline.Pipeline):
 
     def __init__(self):
-        pipeline.Pipeline.__init__(self, common.getPitiviMock(None))
+        pipeline.Pipeline.__init__(self, common.create_pitivi_mock())
         self.state_calls = {}
         self._timeline = mock.MagicMock()
 
diff --git a/tests/test_project.py b/tests/test_project.py
index b84c8e0..a40b13a 100644
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -31,13 +31,11 @@ from pitivi.application import Pitivi
 from pitivi.project import Project
 from pitivi.project import ProjectManager
 from pitivi.utils.misc import uri_is_reachable
-from pitivi.utils.proxy import ProxyingStrategy
 from tests import common
 
 
 def _createRealProject(name=None):
-    app = common.getPitiviMock(proxyingStrategy=ProxyingStrategy.NOTHING)
-    project_manager = ProjectManager(app)
+    project_manager = ProjectManager(common.create_pitivi_mock())
     project_manager.newBlankProject()
     project = project_manager.current_project
     if name:
@@ -444,8 +442,7 @@ class TestProjectSettings(common.TestCase):
         self.assertEqual(Gst.Fraction(1, 1), project.videopar)
 
     def testLoad(self):
-        ptv = common.getPitiviMock(proxyingStrategy=ProxyingStrategy.NOTHING)
-        project = Project(uri="fake.xges", app=ptv)
+        project = Project(uri="fake.xges", app=common.create_pitivi_mock())
         self.assertFalse(project._has_default_video_settings)
         self.assertFalse(project._has_default_audio_settings)
 
diff --git a/tests/test_timeline_timeline.py b/tests/test_timeline_timeline.py
index 57a4025..3cfafdf 100644
--- a/tests/test_timeline_timeline.py
+++ b/tests/test_timeline_timeline.py
@@ -36,7 +36,7 @@ THICK = ui.LAYER_HEIGHT
 
 class BaseTestTimeline(common.TestCase):
     def createTimeline(self):
-        app = common.getPitiviMock()
+        app = common.create_pitivi_mock()
         project_manager = ProjectManager(app)
         project_manager.newBlankProject()
         project = project_manager.current_project


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