Rev 164: Add a new base test case class, that ensures a QApplication is running. in http://bazaar.launchpad.net/~jameinel/bzr-explorer/basic-tests
John Arbash Meinel
john at arbash-meinel.com
Wed Jul 8 20:46:58 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr-explorer/basic-tests
------------------------------------------------------------
revno: 164
revision-id: john at arbash-meinel.com-20090708194653-fm9db3a5zwl0bdzt
parent: john at arbash-meinel.com-20090708194055-h3ld89g6gerv368z
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: basic-tests
timestamp: Wed 2009-07-08 14:46:53 -0500
message:
Add a new base test case class, that ensures a QApplication is running.
This is necessary because most of the gui-related code requires a QApp.
Most notably, all the QPaintDevice stuff needs it.
-------------- next part --------------
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2009-07-08 19:40:55 +0000
+++ b/tests/__init__.py 2009-07-08 19:46:53 +0000
@@ -23,11 +23,31 @@
)
+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()
+
+ 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 load_tests(basic_tests, module, loader):
suite = loader.suiteClass()
suite.addTests(basic_tests)
mod_names = [__name__ + '.' + x for x in [
+ 'test_test_suite',
'test_welcome',
]]
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 19:46:53 +0000
@@ -0,0 +1,27 @@
+# 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 TestTestCaseWithQt(tests.TestCaseWithQt):
+
+ def test_create_qpixmap(self):
+ pixmap = QtGui.QPixmap()
More information about the bazaar-commits
mailing list