From fb664bed0cb835481b435bcc320289538d0f14c7 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Mon, 12 Sep 2011 22:35:39 +0200 Subject: [PATCH] Remove openlyrics tests for easier merging. They will be merged later. --- openlp/core/__init__.py | 35 +- openlp/core/utils/__init__.py | 5 - testing/conftest.py | 139 +----- .../openlyrics/openlyrics_schema.rng | 472 ------------------ testing/resources/openlyrics/validate.py | 26 - testing/resources/songs/openlyrics_test_1.xml | 102 ---- testing/resources/songs/songs.sqlite | Bin 30720 -> 0 bytes testing/test_app.py | 15 +- testing/test_openlyrics.py | 57 --- testing/test_songs_db.py | 76 --- 10 files changed, 29 insertions(+), 898 deletions(-) delete mode 100644 testing/resources/openlyrics/openlyrics_schema.rng delete mode 100755 testing/resources/openlyrics/validate.py delete mode 100644 testing/resources/songs/openlyrics_test_1.xml delete mode 100644 testing/resources/songs/songs.sqlite delete mode 100644 testing/test_openlyrics.py delete mode 100644 testing/test_songs_db.py diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 0bec15678..a5347edeb 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -228,29 +228,26 @@ def main(args=None): help='Set the Qt4 style (passed directly to Qt4).') parser.add_option('--testing', dest='testing', action='store_true', help='Run by testing framework') + # Set up logging + log_path = AppLocation.get_directory(AppLocation.CacheDir) + check_directory_exists(log_path) + filename = os.path.join(log_path, u'openlp.log') + logfile = logging.FileHandler(filename, u'w') + logfile.setFormatter(logging.Formatter( + u'%(asctime)s %(name)-55s %(levelname)-8s %(message)s')) + log.addHandler(logfile) + logging.addLevelName(15, u'Timer') # Parse command line options and deal with them. # Use args supplied programatically if possible. (options, args) = parser.parse_args(args) if args else parser.parse_args() - # Set up logging - # In test mode it is skipped - if not options.testing: - log_path = AppLocation.get_directory(AppLocation.CacheDir) - check_directory_exists(log_path) - filename = os.path.join(log_path, u'openlp.log') - logfile = logging.FileHandler(filename, u'w') - logfile.setFormatter(logging.Formatter( - u'%(asctime)s %(name)-55s %(levelname)-8s %(message)s')) - log.addHandler(logfile) - logging.addLevelName(15, u'Timer') - if options.loglevel.lower() in ['d', 'debug']: - log.setLevel(logging.DEBUG) - print 'Logging to:', filename - elif options.loglevel.lower() in ['w', 'warning']: - log.setLevel(logging.WARNING) - else: - log.setLevel(logging.INFO) - # Deal with other command line options. qt_args = [] + if options.loglevel.lower() in ['d', 'debug']: + log.setLevel(logging.DEBUG) + print 'Logging to:', filename + elif options.loglevel.lower() in ['w', 'warning']: + log.setLevel(logging.WARNING) + else: + log.setLevel(logging.INFO) if options.style: qt_args.extend(['-style', options.style]) # Throw the rest of the arguments at Qt, just in case. diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index fbf185474..3612bb002 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -127,9 +127,6 @@ class AppLocation(object): CacheDir = 6 LanguageDir = 7 - # Base path where data/config/cache dir is located - BaseDir = None - @staticmethod def get_directory(dir_type=1): """ @@ -155,8 +152,6 @@ class AppLocation(object): os.path.abspath(os.path.split(sys.argv[0])[0]), _get_os_dir_path(dir_type)) return os.path.join(app_path, u'i18n') - elif dir_type == AppLocation.DataDir and AppLocation.BaseDir: - return os.path.join(AppLocation.BaseDir, 'data') else: return _get_os_dir_path(dir_type) diff --git a/testing/conftest.py b/testing/conftest.py index 0ba4f34ed..f38018c17 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -30,137 +30,16 @@ Configuration file for pytest framework. """ -import os -import sys -import subprocess -import logging - -import py.path -from PyQt4 import QtCore -from sqlalchemy.orm import clear_mappers - from openlp.core import main as openlp_main -from openlp.core.utils import AppLocation -from openlp.core.lib.db import Manager -from openlp.plugins.songs.lib.db import init_schema - -TESTS_PATH = os.path.dirname(os.path.abspath(__file__)) - -RESOURCES_PATH = os.path.join(TESTS_PATH, 'resources') -SONGS_PATH = os.path.join(RESOURCES_PATH, 'songs') -# class to setup and teardown settings for running openlp tests -class OpenLPRunner(object): - def __init__(self, tmpdir): - self.tmpdir = tmpdir - self._setup_qapp() - self._setup_logging() - self._cleanup_qsettings() - # override data dir of OpenLP - it points to tmpdir of a test case - AppLocation.BaseDir = tmpdir.strpath - - def _setup_qapp(self): - QtCore.QCoreApplication.setOrganizationName(u'OpenLP') - QtCore.QCoreApplication.setOrganizationDomain(u'openlp.org') - QtCore.QCoreApplication.setApplicationName(u'TestOpenLP') - - def _setup_logging(self): - # set up logging to stderr/stdout (console) - _handler = logging.StreamHandler(stream=None) - _handler.setFormatter(logging.Formatter( - u'%(asctime)s %(name)-55s %(levelname)-8s %(message)s')) - logging.addLevelName(15, u'Timer') - log = logging.getLogger() - log.addHandler(_handler) - log.setLevel(logging.DEBUG) - - def _cleanup_qsettings(self): - # Clean up QSettings for all plugins - # The issue with QSettings is that is global for a running process - # and thus it is necessary to clean it before another test case. - # If it would not be cleaned up it could be saved in the system. - s = QtCore.QSettings() - keys = s.allKeys() - for k in keys: - s.setValue(k, None) - - ## Public interface - - def get_songs_db(self, empty=False): - # return initialized db Manager with empty db or db containing - # some example songs - - if not empty: - # copy test data to tmpdir - datadir = self.tmpdir.mkdir(u'data').mkdir(u'songs') - orig_db = py.path.local(SONGS_PATH).join('songs.sqlite') - orig_db.copy(datadir) - - manager = Manager('songs', init_schema) - return manager - - def get_app(self): - # return QGui.QApplication of OpenLP - this object allows - # running different gui tests and allows access to gui objects - # (e.g MainWindow etc.) - # To allow creating multiple instances of OpenLP in one process - # it would be necessary use diffrent configuration and data files. - # Created instance will use your OpenLP settings. +# 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(self): - # clean up code to run after running the test case - self._cleanup_qsettings() - # sqlalchemy allows to map classess to only one database at a time - clear_mappers() - # set data dir to original value - AppLocation.BaseDir = None - - -# Paths with resources for tests -def pytest_funcarg__pth(request): - def setup(): - class Pth(object): - def __init__(self): - self.tests = py.path.local(TESTS_PATH) - self.resources = py.path.local(RESOURCES_PATH) - self.songs = py.path.local(SONGS_PATH) - return Pth() - return request.cached_setup(setup=setup, scope='session') - - -# Test function argument giving access to OpenLP runner -def pytest_funcarg__openlp_runner(request): - def setup(): - return OpenLPRunner(request.getfuncargvalue('tmpdir')) - def teardown(openlp_runner): - openlp_runner.teardown() - return request.cached_setup(setup=setup, teardown=teardown, scope='function') - - -class OpenLyricsValidator(object): - """Validate xml if it conformns to OpenLyrics xml schema.""" - def __init__(self, script, schema): - self.cmd = [sys.executable, script, schema] - - def validate(self, file_path): - self.cmd.append(file_path) - print self.cmd - retcode = subprocess.call(self.cmd) - if retcode == 0: - # xml conforms to schema - return True - else: - # xml has invalid syntax - return False - - -# Test function argument giving access to song database. -def pytest_funcarg__openlyrics_validator(request): - def setup(): - script = os.path.join(RESOURCES_PATH, 'openlyrics', 'validate.py') - schema = os.path.join(RESOURCES_PATH, 'openlyrics', - 'openlyrics_schema.rng') - return OpenLyricsValidator(script, schema) - return request.cached_setup(setup=setup, scope='session') + def teardown(app): + pass + return request.cached_setup(setup=setup, teardown=teardown, scope='session') diff --git a/testing/resources/openlyrics/openlyrics_schema.rng b/testing/resources/openlyrics/openlyrics_schema.rng deleted file mode 100644 index b4a7813fb..000000000 --- a/testing/resources/openlyrics/openlyrics_schema.rng +++ /dev/null @@ -1,472 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - words - music - - - - - - translation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -99 - 99 - - - - - - - - - - - 30 - 250 - - - bpm - - - - - - - text - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - 999 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - optional - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [0-9]+\.[0-9]+(\.[0-9]+)? - - - - - - - - - - - - - - - - - - 1 - - (v[1-9]\d?[a-z]?)|([cpb][a-z]?)|([cpbe][1-9]\d?[a-z]?) - - - - - - - - - - - - - - - - - - - - - - 1 - - - - diff --git a/testing/resources/openlyrics/validate.py b/testing/resources/openlyrics/validate.py deleted file mode 100755 index 116f69454..000000000 --- a/testing/resources/openlyrics/validate.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python - -import sys - -try: - from lxml import etree -except ImportError: - print('Python module "lxml" is required') - exit(1) - - -if len(sys.argv) != 3: - print('Usage: python %s openlyrics_schema.rng xmlfile.xml' % __file__) - exit(1) - - -relaxng_file = sys.argv[1] -xml_file = sys.argv[2] - -relaxng_doc = etree.parse(relaxng_file) -xml_doc = etree.parse(xml_file) - -relaxng = etree.RelaxNG(relaxng_doc) - -relaxng.assertValid(xml_doc) - diff --git a/testing/resources/songs/openlyrics_test_1.xml b/testing/resources/songs/openlyrics_test_1.xml deleted file mode 100644 index d7a9c12ec..000000000 --- a/testing/resources/songs/openlyrics_test_1.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - Jezu Kriste, štědrý kněže - - - M. Jan Hus - - - - - - - - - <span style="-webkit-text-fill-color:red"> - </span> - - - <span style="-webkit-text-fill-color:blue"> - </span> - - - <span style="-webkit-text-fill-color:yellow"> - </span> - - - <span style="-webkit-text-fill-color:#FFA500"> - </span> - - - <strong> - </strong> - - - <em> - </em> - - - <span style="-webkit-text-fill-color:green"> - </span> - - - - - - - Jezu Kriste, štědrý kněže, - s Otcem, Duchem jeden Bože, - štědrost Tvá je naše zboží, - z Tvé milosti. - - - - - Ty jsi v světě, bydlil s námi, - Tvé tělo trpělo rány - za nás za hříšné křesťany, - z Tvé milosti. - - - - - Ó, Tvá dobroto důstojná - a k nám milosti přehojná! - Dáváš nám bohatství mnohá - - - z Tvé milosti. - - - - - - - Ráčils nás sám zastoupiti, - - život za nás položiti, - - tak smrt věčnou zahladiti, - z Tvé milosti. - - - - - Ó, křesťané, z bludů vstaňme, - dané dobro nám poznejme, - k Synu Božímu chvátejme, - k té milosti! - - - - - Chvála budiž Bohu Otci, - Synu jeho téže moci, - Duchu jeho rovné moci, - z též milosti! - - - - diff --git a/testing/resources/songs/songs.sqlite b/testing/resources/songs/songs.sqlite deleted file mode 100644 index f1ae584af22579ee8b55de2c80ce6a96aaae4e43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 30720 zcmeHQ&2JmW72n}XqD4pXcebvoWGKUs2+*b|TXt;AABs#T@`vowbQ;4*i6yxf*Ie$( z+@)-aRRK9EY6M8#!o37W4?6VV07efj&{KV(`5*LDAg3aSqNgB6(YlwuH@i#jiXV2+ zAc(|S)63nNH}l^6%^Py{<_+J~A74~0h2AtuMcJZcBFl~;;NT9=DW#a!N|BA2rHHp=*dvOsN_^ReNzRi^;`yg5_&4SSTFYBAJ7&{ zwJM9v;RYM=D8bP2n*AMxnV&OH(9l2^n0DK?!6~=}P6Of)PQyMt@q;745$H7paQ+kV z?*hE|!4cpHY(4~rNuO|H=)7uLN=8?+h1y?eLDsXXq1V{{yFfw#v_p9)RmLsWxo6v#$TP1_I1r>5D{KE)@nlcP(c@GP8Bw3DN8 zpa|cXg=gfM8`aW^M~rH$w9-bDXvn11jJ9&w$|}VuJzLJggM2jxCG?h(Q*>Ibth{4@ z%+*+BB^q*6F-(i5mTGH2Lv^{nrqJaK5Y?VUL(8;ktW-^F1?nGHV{lQ887s7^S}R3W zgNAA~2G<8a{P5Itj49Dcmr1WKAW*8}$YrW@iJD8#9s#UTnyKV8Rih>a3o5G75b~u^ zqZ!mHEwcAgZB4I)mSrR{DZJ-$K z_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