diff --git a/tests/README.txt b/tests/README.txt new file mode 100644 index 000000000..493b5ccb5 --- /dev/null +++ b/tests/README.txt @@ -0,0 +1,34 @@ +Tests for OpenLP +================ + +This directory contains unit tests for OpenLP. The ``functional`` directory contains functional unit tests. + +Prerequisites +------------- + +In order to run the unit tests, you will need the following Python packages/libraries installed: + + - Mock + - Nose + +On Ubuntu you can simple install the python-mock and python-nose packages. Most other distributions will also have these +packages. On Windows and Mac OS X you will need to use ``pip`` or ``easy_install`` to install these packages. + +Running the Tests +----------------- + +To run the tests, navigate to the root directory of the OpenLP project, and then run the following command:: + + nosetests -v tests + +Or, to run only the functional tests, run the following command:: + + nosetests -v tests/functional + +Or, to run only a particular test suite within a file, run the following command:: + + nosetests -v tests/functional/test_applocation.py + +Finally, to only run a particular test, run the following command:: + + nosetests -v tests/functional/test_applocation.py:TestAppLocation.get_frozen_path_test diff --git a/tests/functional/openlp_core_utils/__init__.py b/tests/functional/openlp_core_utils/__init__.py new file mode 100644 index 000000000..33507f08b --- /dev/null +++ b/tests/functional/openlp_core_utils/__init__.py @@ -0,0 +1 @@ +__author__ = 'raoul' diff --git a/tests/functional/openlp_core_utils/test_applocation.py b/tests/functional/openlp_core_utils/test_applocation.py new file mode 100644 index 000000000..fd0a92fe6 --- /dev/null +++ b/tests/functional/openlp_core_utils/test_applocation.py @@ -0,0 +1,37 @@ +""" +Functional tests to test the AppLocation class and related methods. +""" +import sys +from unittest import TestCase + +from mock import patch +from PyQt4 import QtCore + +from openlp.core.utils import AppLocation, _get_frozen_path + +class TestAppLocation(TestCase): + """ + A test suite to test out various methods around the AppLocation class. + """ + def get_frozen_path_test(self): + """ + Test the _get_frozen_path() function + """ + sys.frozen = None + assert _get_frozen_path(u'frozen', u'not frozen') == u'not frozen', u'Should return "not frozen"' + sys.frozen = 1 + assert _get_frozen_path(u'frozen', u'not frozen') == u'frozen', u'Should return "frozen"' + + def get_data_path_with_custom_location_test(self): + """ + Test the AppLocation.get_data_path() method when a custom location is set in the settings + """ + with patch(u'openlp.core.utils.Settings') as mocked_class: + mocked_settings = mocked_class.return_value + mocked_settings.contains.return_value = True + mocked_settings.value.return_value.toString.return_value = u'test/dir' + data_path = AppLocation.get_data_path() + mocked_settings.contains.assert_called_with(u'advanced/data path') + mocked_settings.value.assert_called_with(u'advanced/data path') + mocked_settings.value.return_value.toString.assert_called_with() + assert data_path == u'test/dir', u'Result should be "test/dir"'