Rev 177: Merge basic-tests updates in http://bazaar.launchpad.net/~jameinel/bzr-explorer/wt_model

John Arbash Meinel john at arbash-meinel.com
Thu Jul 9 18:45:03 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr-explorer/wt_model

------------------------------------------------------------
revno: 177 [merge]
revision-id: john at arbash-meinel.com-20090709174453-tk9eahp0g02llou9
parent: john at arbash-meinel.com-20090708193921-d1nkn5u02z9ug89x
parent: john at arbash-meinel.com-20090708202810-7k51txb3t0t2qggj
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: wt_model
timestamp: Thu 2009-07-09 12:44:53 -0500
message:
  Merge basic-tests updates
added:
  tests/test_test_suite.py       test_test_suite.py-20090708194623-luogz9w9offd33nt-1
renamed:
  tests/test_welcome_model.py => tests/test_welcome.py test_welcome_model.p-20090707193000-35v80h2r8td5k56a-2
modified:
  tests/__init__.py              __init__.py-20090707193000-35v80h2r8td5k56a-1
-------------- next part --------------
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2009-07-07 20:51:58 +0000
+++ b/tests/__init__.py	2009-07-09 17:44:53 +0000
@@ -23,12 +23,65 @@
     )
 
 
+class TestCaseWithQt(TestCaseWithTransport):
+    """Many GUI functions require a QApplication to be running.
+
+    This class ensures a QtApplication is running during setUp.
+    """
+
+    _app = None
+
+    def setUp(self):
+        super(TestCaseWithQt, self).setUp()
+        self.ensureApp()
+        self.logger = self.createLogger()
+
+    def ensureApp(self):
+        if TestCaseWithQt._app is None:
+            from PyQt4 import QtGui
+            TestCaseWithQt._app = QtGui.QApplication(['bzr-explorer-test-app'])
+            # It seems we can leave it running.
+
+    def createLogger(self, *args):
+        from PyQt4 import QtCore
+
+        class ConnectionLogger(QtCore.QObject):
+
+            def __init__(self, *args):
+                QtCore.QObject.__init__(self, *args)
+                # A log of actions that have occurrred
+                self.log = []
+
+            def createNamedSlot(self, signal_name):
+                """Create a new slot, which tracks the signal name given.
+
+                :param signal_name: The name of the signal we are connecting
+                :return: A function that can be used as a signal to this logger.
+                """
+                def named_slot(*args):
+                    self.log.append((signal_name,) + args)
+                return named_slot
+
+            def connectToNamedSlot(self, signal, source):
+                """Create a new named slot, and connect the signal from source.
+
+                :param signal: The value to pass to QtCore.SIGNAL, this will
+                    also be the name logged when the signal is activated.
+                :param source: An object that can generate the given signal.
+                """
+                slot = self.createNamedSlot(signal)
+                QtCore.QObject.connect(source, QtCore.SIGNAL(signal), slot)
+
+        return ConnectionLogger(*args)
+
+
 def load_tests(basic_tests, module, loader):
     suite = loader.suiteClass()
     suite.addTests(basic_tests)
 
     mod_names = [__name__ + '.' + x for x in [
-        'test_welcome_model',
+        'test_test_suite',
+        'test_welcome',
         'test_wt_model',
     ]]
     suite.addTests(loader.loadTestsFromModuleNames(mod_names))

=== added file 'tests/test_test_suite.py'
--- a/tests/test_test_suite.py	1970-01-01 00:00:00 +0000
+++ b/tests/test_test_suite.py	2009-07-08 20:28:10 +0000
@@ -0,0 +1,66 @@
+# Copyright (C) 2009 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Tests for the testing infrastructure in bzr-explorer."""
+
+from PyQt4 import QtCore, QtGui
+
+from bzrlib.plugins.explorer import tests
+
+
+class _Emitter(QtCore.QObject):
+
+    def trigger_foo(self):
+        self.emit(QtCore.SIGNAL('foo()'))
+
+    def trigger_bar(self, arg1, arg2):
+        self.emit(QtCore.SIGNAL('bar(int, int)'), arg1, arg2)
+
+
+class TestTestCaseWithQt(tests.TestCaseWithQt):
+
+    def test_create_qpixmap(self):
+        pixmap = QtGui.QPixmap()
+
+    def test_logger_named_slot(self):
+        slot = self.logger.createNamedSlot('trapping_foo')
+        emitter = _Emitter()
+        QtCore.QObject.connect(emitter, QtCore.SIGNAL('foo()'), slot)
+        self.assertEqual([], self.logger.log)
+        emitter.trigger_foo()
+        self.assertEqual([('trapping_foo',)], self.logger.log)
+        emitter.trigger_bar(1, 2) # not connected
+        self.assertEqual([('trapping_foo',)], self.logger.log)
+        emitter.trigger_foo()
+        self.assertEqual([('trapping_foo',), ('trapping_foo',)],
+                         self.logger.log)
+        slot = self.logger.createNamedSlot('trapping_bar')
+        QtCore.QObject.connect(emitter, QtCore.SIGNAL('bar(int, int)'), slot)
+        emitter.trigger_bar(1, 2)
+        self.assertEqual([('trapping_foo',), ('trapping_foo',),
+                          ('trapping_bar', 1, 2),
+                         ], self.logger.log)
+
+    def test_connectToNamedSlot(self):
+        emitter = _Emitter()
+        self.logger.connectToNamedSlot('foo()', emitter)
+        self.logger.connectToNamedSlot('bar(int, int)', emitter)
+        emitter.trigger_foo()
+        self.assertEqual([('foo()',)], self.logger.log)
+        emitter.trigger_bar(3, 4)
+        self.assertEqual([('foo()',), ('bar(int, int)', 3, 4)],
+                         self.logger.log)
+

=== renamed file 'tests/test_welcome_model.py' => 'tests/test_welcome.py'


More information about the bazaar-commits mailing list