[pitivi] tests_: Update test_application to use mock



commit 0a50a802d80cdd23dcc5d615580ba010c2c490a3
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Mon Jan 2 00:19:56 2017 +0100

    tests_: Update test_application to use mock
    
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Differential Revision: https://phabricator.freedesktop.org/D1579

 pitivi/application.py     |    4 +-
 pre-commit.hook           |    1 -
 tests/test_application.py |   54 ++++++++++++++++++--------------------------
 3 files changed, 24 insertions(+), 35 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index 6ffe44a..82831ef 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -294,9 +294,9 @@ class Pitivi(Gtk.Application, Loggable):
         """Checks online for new versions of the app."""
         self.info("Requesting version information async")
         giofile = Gio.File.new_for_uri(RELEASES_URL)
-        giofile.load_contents_async(None, self._versionInfoReceivedCb, None)
+        giofile.load_contents_async(None, self._version_info_received_cb, None)
 
-    def _versionInfoReceivedCb(self, giofile, result, user_data):
+    def _version_info_received_cb(self, giofile, result, user_data):
         try:
             raw = giofile.load_contents_finish(result)[1]
             if not isinstance(raw, str):
diff --git a/pre-commit.hook b/pre-commit.hook
index f542037..8904151 100755
--- a/pre-commit.hook
+++ b/pre-commit.hook
@@ -48,7 +48,6 @@ pitivi/viewer/overlay_stack.py
 pitivi/viewer/title_overlay.py
 pitivi/viewer/viewer.py
 tests/common.py
-tests/test_application.py
 tests/test_check.py
 tests/test_clipproperties.py
 tests/test_common.py
diff --git a/tests/test_application.py b/tests/test_application.py
index 4e750d5..4258996 100644
--- a/tests/test_application.py
+++ b/tests/test_application.py
@@ -16,64 +16,54 @@
 # License along with this program; if not, write to the
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
+"""Tests for the application module."""
+# pylint: disable=missing-docstring,protected-access,no-self-use
+from unittest import mock
+
 from pitivi import application
 from pitivi import configure
 from tests import common
 
 
-class MockGioFile(object):
-
-    def load_contents_finish(self, result):
-        return (True, result)
-
-
 class TestPitivi(common.TestCase):
 
-    def testVersionInfo(self):
+    def call_version_info_received(self, version_info):
         app = application.Pitivi()
-        app._checkVersion()
-        self.assertTrue(app.isLatest())
+        giofile = mock.Mock()
+        giofile.load_contents_finish.return_value = (True, version_info)
+        app._version_info_received_cb(giofile, result=None, user_data=None)
+        return app
 
+    def test_version_info(self):
         app = application.Pitivi()
-        app._checkVersion()
-        app._versionInfoReceivedCb(MockGioFile(), "invalid", None)
         self.assertTrue(app.isLatest())
 
-        app = application.Pitivi()
-        app._checkVersion()
-        app._versionInfoReceivedCb(
-            MockGioFile(), "%s=CURRENT" % configure.VERSION, None)
+        app = self.call_version_info_received("invalid")
+        self.assertTrue(app.isLatest())
+
+        app = self.call_version_info_received(
+            "%s=CURRENT" % configure.VERSION)
         self.assertTrue(app.isLatest())
         self.assertEqual(configure.VERSION, app.getLatest())
 
-        app = application.Pitivi()
-        app._checkVersion()
-        app._versionInfoReceivedCb(
-            MockGioFile(), "%s=current\n0=supported" % configure.VERSION, None)
+        app = self.call_version_info_received(
+            "%s=current\n0=supported" % configure.VERSION)
         self.assertTrue(app.isLatest())
         self.assertEqual(configure.VERSION, app.getLatest())
 
-        app = application.Pitivi()
-        app._checkVersion()
-        app._versionInfoReceivedCb(MockGioFile(), "999.0=CURRENT", None)
+        app = self.call_version_info_received("999.0=CURRENT")
         self.assertFalse(app.isLatest())
         self.assertEqual("999.0", app.getLatest())
 
-        app = application.Pitivi()
-        app._checkVersion()
-        app._versionInfoReceivedCb(
-            MockGioFile(), "999.0=CURRENT\n%s=SUPPORTED" % configure.VERSION, None)
+        app = self.call_version_info_received(
+            "999.0=CURRENT\n%s=SUPPORTED" % configure.VERSION)
         self.assertFalse(app.isLatest())
         self.assertEqual("999.0", app.getLatest())
 
-        app = application.Pitivi()
-        app._checkVersion()
-        app._versionInfoReceivedCb(MockGioFile(), "0.91=current", None)
+        app = self.call_version_info_received("0.91=current")
         self.assertTrue(app.isLatest())
         self.assertEqual("0.91", app.getLatest())
 
-        app = application.Pitivi()
-        app._checkVersion()
-        app._versionInfoReceivedCb(MockGioFile(), "0.100000000=current", None)
+        app = self.call_version_info_received("0.100000000=current")
         self.assertFalse(app.isLatest())
         self.assertEqual("0.100000000", app.getLatest())


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