Merge lp:~tomasgroth/openlp/zionworx-fix-22 into lp:openlp/2.2

Proposed by Tomas Groth
Status: Merged
Merged at revision: 2567
Proposed branch: lp:~tomasgroth/openlp/zionworx-fix-22
Merge into: lp:openlp/2.2
Diff against target: 167 lines (+102/-7)
4 files modified
openlp/plugins/songs/lib/importers/zionworx.py (+7/-7)
tests/functional/openlp_plugins/songs/test_zionworximport.py (+20/-0)
tests/resources/zionworxsongs/zionworx.csv (+45/-0)
tests/resources/zionworxsongs/zionworx.json (+30/-0)
To merge this branch: bzr merge lp:~tomasgroth/openlp/zionworx-fix-22
Reviewer Review Type Date Requested Status
Tomas Groth Approve
Tim Bentley Approve
Review via email: mp+276061@code.launchpad.net

Description of the change

Make the zionworx importer work under python3.

To post a comment you must log in.
Revision history for this message
Tomas Groth (tomasgroth) wrote :

lp:~tomasgroth/openlp/zionworx-fix-22 (revision 2564)
[SUCCESS] https//ci.openlp.io/job/Branch-01-Pull/1165/
[SUCCESS] https//ci.openlp.io/job/Branch-02-Functional-Tests/1088/
[SUCCESS] https//ci.openlp.io/job/Branch-03-Interface-Tests/1029/
[SUCCESS] https//ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/876/
[SUCCESS] https//ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/472/
[SUCCESS] https//ci.openlp.io/job/Branch-05a-Code_Analysis/592/
[SUCCESS] https//ci.openlp.io/job/Branch-05b-Test_Coverage/463/

Revision history for this message
Tim Bentley (trb143) :
review: Approve
Revision history for this message
Tomas Groth (tomasgroth) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/plugins/songs/lib/importers/zionworx.py'
--- openlp/plugins/songs/lib/importers/zionworx.py 2015-03-09 20:57:39 +0000
+++ openlp/plugins/songs/lib/importers/zionworx.py 2015-10-28 21:55:40 +0000
@@ -75,7 +75,8 @@
75 """75 """
76 Receive a CSV file (from a ZionWorx database dump) to import.76 Receive a CSV file (from a ZionWorx database dump) to import.
77 """77 """
78 with open(self.import_source, 'rb') as songs_file:78 # Encoding should always be ISO-8859-1
79 with open(self.import_source, 'rt', encoding='ISO-8859-1') as songs_file:
79 field_names = ['SongNum', 'Title1', 'Title2', 'Lyrics', 'Writer', 'Copyright', 'Keywords',80 field_names = ['SongNum', 'Title1', 'Title2', 'Lyrics', 'Writer', 'Copyright', 'Keywords',
80 'DefaultStyle']81 'DefaultStyle']
81 songs_reader = csv.DictReader(songs_file, field_names)82 songs_reader = csv.DictReader(songs_file, field_names)
@@ -112,10 +113,10 @@
112 if line and not line.isspace():113 if line and not line.isspace():
113 verse += line + '\n'114 verse += line + '\n'
114 elif verse:115 elif verse:
115 self.add_verse(verse)116 self.add_verse(verse, 'v')
116 verse = ''117 verse = ''
117 if verse:118 if verse:
118 self.add_verse(verse)119 self.add_verse(verse, 'v')
119 title = self.title120 title = self.title
120 if not self.finish():121 if not self.finish():
121 self.log_error(translate('SongsPlugin.ZionWorxImport', 'Record %d') % index +122 self.log_error(translate('SongsPlugin.ZionWorxImport', 'Record %d') % index +
@@ -123,8 +124,7 @@
123124
124 def _decode(self, str):125 def _decode(self, str):
125 """126 """
126 Decodes CSV input to unicode, stripping all control characters (except new lines).127 Strips all control characters (except new lines).
127 """128 """
128 # This encoding choice seems OK. ZionWorx has no option for setting the129 # ZionWorx has no option for setting the encoding for its songs, so we assume encoding is always the same.
129 # encoding for its songs, so we assume encoding is always the same.130 return str.translate(CONTROL_CHARS_MAP)
130 return str(str, 'cp1252').translate(CONTROL_CHARS_MAP)
131131
=== modified file 'tests/functional/openlp_plugins/songs/test_zionworximport.py'
--- tests/functional/openlp_plugins/songs/test_zionworximport.py 2015-01-18 13:39:21 +0000
+++ tests/functional/openlp_plugins/songs/test_zionworximport.py 2015-10-28 21:55:40 +0000
@@ -22,14 +22,19 @@
22"""22"""
23This module contains tests for the ZionWorx song importer.23This module contains tests for the ZionWorx song importer.
24"""24"""
25import os
2526
26from unittest import TestCase27from unittest import TestCase
2728
28from tests.functional import MagicMock, patch29from tests.functional import MagicMock, patch
30from tests.helpers.songfileimport import SongImportTestHelper
29from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport31from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport
30from openlp.plugins.songs.lib.importers.songimport import SongImport32from openlp.plugins.songs.lib.importers.songimport import SongImport
31from openlp.core.common import Registry33from openlp.core.common import Registry
3234
35TEST_PATH = os.path.abspath(
36 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'zionworxsongs'))
37
3338
34class TestZionWorxImport(TestCase):39class TestZionWorxImport(TestCase):
35 """40 """
@@ -54,3 +59,18 @@
5459
55 # THEN: The importer should be an instance of SongImport60 # THEN: The importer should be an instance of SongImport
56 self.assertIsInstance(importer, SongImport)61 self.assertIsInstance(importer, SongImport)
62
63
64class TestZionWorxFileImport(SongImportTestHelper):
65
66 def __init__(self, *args, **kwargs):
67 self.importer_class_name = 'ZionWorxImport'
68 self.importer_module_name = 'zionworx'
69 super(TestZionWorxFileImport, self).__init__(*args, **kwargs)
70
71 def test_song_import(self):
72 """
73 Test that loading an ZionWorx file works correctly on various files
74 """
75 self.file_import(os.path.join(TEST_PATH, 'zionworx.csv'),
76 self.load_external_result_data(os.path.join(TEST_PATH, 'zionworx.json')))
5777
=== added directory 'tests/resources/zionworxsongs'
=== added file 'tests/resources/zionworxsongs/zionworx.csv'
--- tests/resources/zionworxsongs/zionworx.csv 1970-01-01 00:00:00 +0000
+++ tests/resources/zionworxsongs/zionworx.csv 2015-10-28 21:55:40 +0000
@@ -0,0 +1,45 @@
1"1","Crown Him With Many Crowns",,"Crown him with many crowns,
2The Lamb upon His throne;
3Hark, how the heavenly anthem drowns
4All music but its own!
5Awake, my soul, and sing
6Of Him who died for thee,
7And hail Him as thy matchless King
8Through all eternity.
9
10Crown Him the Lord of life,
11Who triumphed o'er the grave
12And rose victorious in the strife
13For those He came to save:
14His glories now we sing,
15Who died and rose on high,
16Who died eternal life to bring
17And lives that death may die.
18
19Crown Him the Lord of love;
20Behold His hands and side,
21Those wounds yet visible above
22In beauty glorified:
23No angel in the sky
24Can fully bear that sight,
25But downward bends His burning eye
26At mysteries so bright.
27
28Crown Him the Lord of peace,
29Whose power a sceptre sways
30From pole to pole, that wars may cease,
31And all be prayer and praise:
32His reign shall know no end,
33And round His piercèd feet
34Fair flowers of paradise extend
35Their fragrance ever sweet.
36
37Crown Him the Lord of years,
38The Potentate of time,
39Creator of the rolling spheres,
40Ineffably sublime!
41All hail, Redeemer, hail!
42For Thou hast died for me;
43Thy praise shall never, never fail
44Throughout eternity.
45","Matthew Bridges","Public Domain",,
046
=== added file 'tests/resources/zionworxsongs/zionworx.json'
--- tests/resources/zionworxsongs/zionworx.json 1970-01-01 00:00:00 +0000
+++ tests/resources/zionworxsongs/zionworx.json 2015-10-28 21:55:40 +0000
@@ -0,0 +1,30 @@
1{
2 "authors": [
3 "Matthew Bridges"
4 ],
5 "copyright": "Public Domain",
6 "title": "Crown Him With Many Crowns",
7 "verse_order_list": [],
8 "verses": [
9 [
10 "Crown him with many crowns,\nThe Lamb upon His throne;\nHark, how the heavenly anthem drowns\nAll music but its own!\nAwake, my soul, and sing\nOf Him who died for thee,\nAnd hail Him as thy matchless King\nThrough all eternity.\n",
11 "v"
12 ],
13 [
14 "Crown Him the Lord of life,\nWho triumphed o'er the grave\nAnd rose victorious in the strife\nFor those He came to save:\nHis glories now we sing,\nWho died and rose on high,\nWho died eternal life to bring\nAnd lives that death may die.\n",
15 "v"
16 ],
17 [
18 "Crown Him the Lord of love;\nBehold His hands and side,\nThose wounds yet visible above\nIn beauty glorified:\nNo angel in the sky\nCan fully bear that sight,\nBut downward bends His burning eye\nAt mysteries so bright.\n",
19 "v"
20 ],
21 [
22 "Crown Him the Lord of peace,\nWhose power a sceptre sways\nFrom pole to pole, that wars may cease,\nAnd all be prayer and praise:\nHis reign shall know no end,\nAnd round His piercèd feet\nFair flowers of paradise extend\nTheir fragrance ever sweet.\n",
23 "v"
24 ],
25 [
26 "Crown Him the Lord of years,\nThe Potentate of time,\nCreator of the rolling spheres,\nIneffably sublime!\nAll hail, Redeemer, hail!\nFor Thou hast died for me;\nThy praise shall never, never fail\nThroughout eternity.\n",
27 "v"
28 ]
29 ]
30}

Subscribers

People subscribed via source and target branches

to all changes: