add test for openlyrics export

This commit is contained in:
Martin Zibricky 2011-09-06 00:31:09 +02:00
parent 15b63b8279
commit e491e77981
3 changed files with 45 additions and 4 deletions

View File

@ -31,6 +31,8 @@ Configuration file for pytest framework.
""" """
import os import os
import sys
import subprocess
import logging import logging
import random import random
import string import string
@ -58,6 +60,18 @@ log.addHandler(_handler)
log.setLevel(logging.DEBUG) log.setLevel(logging.DEBUG)
# 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='module')
# Test function argument to make openlp gui instance persistent for all tests. # Test function argument to make openlp gui instance persistent for all tests.
# Test cases in module have to access the same instance. To allow creating # Test cases in module have to access the same instance. To allow creating
# multiple # multiple
@ -115,3 +129,30 @@ def pytest_funcarg__songs_db(request):
# sqlalchemy allows to map classess to only one database at a time # sqlalchemy allows to map classess to only one database at a time
clear_mappers() clear_mappers()
return request.cached_setup(setup=setup, teardown=teardown, scope='function') 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')

View File

@ -34,7 +34,7 @@ from openlp.core import OpenLP
from openlp.core.ui.mainwindow import MainWindow from openlp.core.ui.mainwindow import MainWindow
def test_start_app(openlpapp): #def test_start_app(openlpapp):
assert type(openlpapp) == OpenLP #assert type(openlpapp) == OpenLP
assert type(openlpapp.mainWindow) == MainWindow #assert type(openlpapp.mainWindow) == MainWindow
assert unicode(openlpapp.mainWindow.windowTitle()) == u'OpenLP 2.0' #assert unicode(openlpapp.mainWindow.windowTitle()) == u'OpenLP 2.0'