First couple of (example) tests and a README file to go with it.

This commit is contained in:
Raoul Snyman 2012-12-05 20:52:31 +02:00
parent 0450866e73
commit 8a4f143878
3 changed files with 72 additions and 0 deletions

34
tests/README.txt Normal file
View File

@ -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

View File

@ -0,0 +1 @@
__author__ = 'raoul'

View File

@ -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"'