2011-09-06 10:49:15 +00:00
|
|
|
#!/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 #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
OpenLyrics import/export tests
|
|
|
|
"""
|
|
|
|
|
|
|
|
from lxml import etree
|
|
|
|
|
|
|
|
from openlp.plugins.songs.lib.db import Song
|
|
|
|
from openlp.plugins.songs.lib import OpenLyrics
|
|
|
|
|
2011-09-11 21:53:19 +00:00
|
|
|
|
|
|
|
def test_openlyrics_export(openlp_runner, openlyrics_validator, pth, tmpdir):
|
2011-09-06 10:49:15 +00:00
|
|
|
# export song to file
|
|
|
|
f = tmpdir.join('out.xml')
|
2011-09-11 21:53:19 +00:00
|
|
|
db = openlp_runner.get_songs_db()
|
2011-09-06 10:49:15 +00:00
|
|
|
s = db.get_all_objects(Song)[0]
|
|
|
|
o = OpenLyrics(db)
|
|
|
|
xml = o.song_to_xml(s)
|
|
|
|
tree = etree.ElementTree(etree.fromstring(xml))
|
|
|
|
tree.write(open(f.strpath, u'w'), encoding=u'utf-8', xml_declaration=True,
|
|
|
|
pretty_print=True)
|
|
|
|
# validate file
|
2011-09-07 23:16:14 +00:00
|
|
|
assert openlyrics_validator.validate(f.strpath) == True
|
2011-09-07 20:54:53 +00:00
|
|
|
# string comparison with original file line by line
|
2011-09-06 10:49:15 +00:00
|
|
|
f_orig = pth.songs.join('openlyrics_test_1.xml')
|
2011-09-07 20:54:53 +00:00
|
|
|
for l, l_orig in zip(f.readlines(), f_orig.readlines()):
|
|
|
|
# skip line with item modifiedDate - it is unique everytime
|
|
|
|
if l.startswith('<song xmlns='):
|
|
|
|
continue
|
|
|
|
assert l == l_orig
|