diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 896066e73..01d34956e 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -261,8 +261,10 @@ def main(args=None): app.setApplicationName(u'OpenLP') app.setApplicationVersion(get_application_version()[u'version']) # Instance check - if app.isAlreadyRunning(): - sys.exit() + if not options.testing: + # Instance check + if app.isAlreadyRunning(): + sys.exit() # First time checks in settings if not QtCore.QSettings().value(u'general/has run wizard', QtCore.QVariant(False)).toBool(): @@ -284,5 +286,7 @@ def main(args=None): # Do not run method app.exec_() when running gui tests if options.testing: app.run(qt_args, testing=True) + # For gui tests we need access to window intances and their components + return app else: sys.exit(app.run(qt_args)) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index 5f2e4c148..14d27fb81 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -80,6 +80,7 @@ OPTIONAL_MODULES = [ ('sqlite', ' (SQLite 2 support)'), ('MySQLdb', ' (MySQL support)'), ('psycopg2', ' (PostgreSQL support)'), + ('pytest', ' (testing framework)'), ] w = sys.stdout.write diff --git a/testing/conftest.py b/testing/conftest.py new file mode 100644 index 000000000..f38018c17 --- /dev/null +++ b/testing/conftest.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2011 Raoul Snyman # +# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, # +# Armin Köhler, Joshua Millar, Stevan Pettit, Andreas Preikschat, Mattias # +# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund # +# --------------------------------------------------------------------------- # +# 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; version 2 of the License. # +# # +# 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 # +############################################################################### + +""" +Configuration file for pytest framework. +""" + +from openlp.core import main as openlp_main + + +# Test function argument to make openlp gui instance persistent for all tests. +# All test cases have to access the same instance. To allow create multiple +# instances it would be necessary use diffrent configuraion and data files. +# Created instance will use your OpenLP settings. +def pytest_funcarg__openlpapp(request): + def setup(): + return openlp_main(['--testing']) + def teardown(app): + pass + return request.cached_setup(setup=setup, teardown=teardown, scope='session') diff --git a/testing/run.py b/testing/run.py new file mode 100755 index 000000000..1f0f54858 --- /dev/null +++ b/testing/run.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2011 Raoul Snyman # +# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, # +# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias # +# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund # +# --------------------------------------------------------------------------- # +# 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; version 2 of the License. # +# # +# 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 # +############################################################################### + +""" +This script is used to run set of automated tests of OpenLP. To start tests, +simply run this script:: + + @:~$ ./run.py + +""" + +import os.path +import sys + +TESTS_PATH = os.path.dirname(os.path.abspath(__file__)) +SRC_PATH = os.path.join(TESTS_PATH, '..') + +PYTEST_OPTIONS = [TESTS_PATH] + +# Extend python PATH with openlp source +sys.path.insert(0, SRC_PATH) + +# Python testing framework +# http://pytest.org +import pytest + + +def main(): + print 'pytest options:', PYTEST_OPTIONS + pytest.main(PYTEST_OPTIONS) + + +if __name__ == u'__main__': + main() diff --git a/testing/test_app.py b/testing/test_app.py new file mode 100644 index 000000000..00cd744ba --- /dev/null +++ b/testing/test_app.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2011 Raoul Snyman # +# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, # +# Armin Köhler, Joshua Millar, Stevan Pettit, Andreas Preikschat, Mattias # +# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund # +# --------------------------------------------------------------------------- # +# 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; version 2 of the License. # +# # +# 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 # +############################################################################### + +from openlp.core import OpenLP +from openlp.core.ui.mainwindow import MainWindow + + +def test_start_app(openlpapp): + assert type(openlpapp) == OpenLP + assert type(openlpapp.mainWindow) == MainWindow + assert unicode(openlpapp.mainWindow.windowTitle()) == u'OpenLP 2.0'