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
1=== modified file 'openlp/plugins/songs/lib/importers/zionworx.py'
2--- openlp/plugins/songs/lib/importers/zionworx.py 2015-03-09 20:57:39 +0000
3+++ openlp/plugins/songs/lib/importers/zionworx.py 2015-10-28 21:55:40 +0000
4@@ -75,7 +75,8 @@
5 """
6 Receive a CSV file (from a ZionWorx database dump) to import.
7 """
8- with open(self.import_source, 'rb') as songs_file:
9+ # Encoding should always be ISO-8859-1
10+ with open(self.import_source, 'rt', encoding='ISO-8859-1') as songs_file:
11 field_names = ['SongNum', 'Title1', 'Title2', 'Lyrics', 'Writer', 'Copyright', 'Keywords',
12 'DefaultStyle']
13 songs_reader = csv.DictReader(songs_file, field_names)
14@@ -112,10 +113,10 @@
15 if line and not line.isspace():
16 verse += line + '\n'
17 elif verse:
18- self.add_verse(verse)
19+ self.add_verse(verse, 'v')
20 verse = ''
21 if verse:
22- self.add_verse(verse)
23+ self.add_verse(verse, 'v')
24 title = self.title
25 if not self.finish():
26 self.log_error(translate('SongsPlugin.ZionWorxImport', 'Record %d') % index +
27@@ -123,8 +124,7 @@
28
29 def _decode(self, str):
30 """
31- Decodes CSV input to unicode, stripping all control characters (except new lines).
32+ Strips all control characters (except new lines).
33 """
34- # This encoding choice seems OK. ZionWorx has no option for setting the
35- # encoding for its songs, so we assume encoding is always the same.
36- return str(str, 'cp1252').translate(CONTROL_CHARS_MAP)
37+ # ZionWorx has no option for setting the encoding for its songs, so we assume encoding is always the same.
38+ return str.translate(CONTROL_CHARS_MAP)
39
40=== modified file 'tests/functional/openlp_plugins/songs/test_zionworximport.py'
41--- tests/functional/openlp_plugins/songs/test_zionworximport.py 2015-01-18 13:39:21 +0000
42+++ tests/functional/openlp_plugins/songs/test_zionworximport.py 2015-10-28 21:55:40 +0000
43@@ -22,14 +22,19 @@
44 """
45 This module contains tests for the ZionWorx song importer.
46 """
47+import os
48
49 from unittest import TestCase
50
51 from tests.functional import MagicMock, patch
52+from tests.helpers.songfileimport import SongImportTestHelper
53 from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport
54 from openlp.plugins.songs.lib.importers.songimport import SongImport
55 from openlp.core.common import Registry
56
57+TEST_PATH = os.path.abspath(
58+ os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'zionworxsongs'))
59+
60
61 class TestZionWorxImport(TestCase):
62 """
63@@ -54,3 +59,18 @@
64
65 # THEN: The importer should be an instance of SongImport
66 self.assertIsInstance(importer, SongImport)
67+
68+
69+class TestZionWorxFileImport(SongImportTestHelper):
70+
71+ def __init__(self, *args, **kwargs):
72+ self.importer_class_name = 'ZionWorxImport'
73+ self.importer_module_name = 'zionworx'
74+ super(TestZionWorxFileImport, self).__init__(*args, **kwargs)
75+
76+ def test_song_import(self):
77+ """
78+ Test that loading an ZionWorx file works correctly on various files
79+ """
80+ self.file_import(os.path.join(TEST_PATH, 'zionworx.csv'),
81+ self.load_external_result_data(os.path.join(TEST_PATH, 'zionworx.json')))
82
83=== added directory 'tests/resources/zionworxsongs'
84=== added file 'tests/resources/zionworxsongs/zionworx.csv'
85--- tests/resources/zionworxsongs/zionworx.csv 1970-01-01 00:00:00 +0000
86+++ tests/resources/zionworxsongs/zionworx.csv 2015-10-28 21:55:40 +0000
87@@ -0,0 +1,45 @@
88+"1","Crown Him With Many Crowns",,"Crown him with many crowns,
89+The Lamb upon His throne;
90+Hark, how the heavenly anthem drowns
91+All music but its own!
92+Awake, my soul, and sing
93+Of Him who died for thee,
94+And hail Him as thy matchless King
95+Through all eternity.
96+
97+Crown Him the Lord of life,
98+Who triumphed o'er the grave
99+And rose victorious in the strife
100+For those He came to save:
101+His glories now we sing,
102+Who died and rose on high,
103+Who died eternal life to bring
104+And lives that death may die.
105+
106+Crown Him the Lord of love;
107+Behold His hands and side,
108+Those wounds yet visible above
109+In beauty glorified:
110+No angel in the sky
111+Can fully bear that sight,
112+But downward bends His burning eye
113+At mysteries so bright.
114+
115+Crown Him the Lord of peace,
116+Whose power a sceptre sways
117+From pole to pole, that wars may cease,
118+And all be prayer and praise:
119+His reign shall know no end,
120+And round His piercèd feet
121+Fair flowers of paradise extend
122+Their fragrance ever sweet.
123+
124+Crown Him the Lord of years,
125+The Potentate of time,
126+Creator of the rolling spheres,
127+Ineffably sublime!
128+All hail, Redeemer, hail!
129+For Thou hast died for me;
130+Thy praise shall never, never fail
131+Throughout eternity.
132+","Matthew Bridges","Public Domain",,
133
134=== added file 'tests/resources/zionworxsongs/zionworx.json'
135--- tests/resources/zionworxsongs/zionworx.json 1970-01-01 00:00:00 +0000
136+++ tests/resources/zionworxsongs/zionworx.json 2015-10-28 21:55:40 +0000
137@@ -0,0 +1,30 @@
138+{
139+ "authors": [
140+ "Matthew Bridges"
141+ ],
142+ "copyright": "Public Domain",
143+ "title": "Crown Him With Many Crowns",
144+ "verse_order_list": [],
145+ "verses": [
146+ [
147+ "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",
148+ "v"
149+ ],
150+ [
151+ "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",
152+ "v"
153+ ],
154+ [
155+ "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",
156+ "v"
157+ ],
158+ [
159+ "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",
160+ "v"
161+ ],
162+ [
163+ "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",
164+ "v"
165+ ]
166+ ]
167+}

Subscribers

People subscribed via source and target branches

to all changes: