Unicode chars in my testcase work OK

This commit is contained in:
Martin Thompson 2010-06-25 19:20:45 +01:00
parent 76e3538127
commit baec9d5c2f
3 changed files with 18 additions and 13 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<song>
<title>Martins Test</title>
<author>Martin Thompson</author>
<author>MartiÑ Thómpson</author>
<copyright>2010 Martin Thompson</copyright>
<hymn_number>1</hymn_number>
<presentation>V1 C V2 C2 V3 B1 V1</presentation>
@ -25,8 +25,8 @@
2 V2 Line 2
[3]
V3 Line 1
V3 Line 2
V3 Line 1
V3 Line 2
[b1]
Bridge 1

View File

@ -9,9 +9,9 @@ import codecs
def opensong_import_lots():
ziploc=u'/home/mjt/openlp/OpenSong_Data/'
files=[]
files.extend(glob(ziploc+u'Songs.zip'))
files.extend(glob(ziploc+u'SOF.zip'))
# files.extend(glob(ziploc+u'spanish_songs_for_opensong.zip'))
# files.extend(glob(ziploc+u'Songs.zip'))
# files.extend(glob(ziploc+u'SOF.zip'))
files.extend(glob(ziploc+u'spanish_songs_for_opensong.zip'))
# files.extend(glob(ziploc+u'opensong_*.zip'))
errfile=codecs.open(u'import_lots_errors.txt', u'w', u'utf8')
manager=SongManager()
@ -19,31 +19,35 @@ def opensong_import_lots():
print u'Importing', file
z=ZipFile(file, u'r')
for song in z.infolist():
filename=song.filename.decode('cp852')
# need to handle unicode filenames (CP437 - Winzip does this)
filename=song.filename#.decode('cp852')
parts=os.path.split(filename)
if parts[-1] == u'':
#No final part => directory
continue
# xxx need to handle unicode filenames (CP437?? Winzip does this)
print " ", file, ":",filename,
songfile=z.open(song)
# songfile=z.open(song)
z.extract(song)
songfile=open(filename, u'r')
o=OpenSongImport(manager)
try:
o.do_import_file(songfile)
except:
print "Failure",
errfile.write(u'Failure: %s:%s\n' %(file, filename))
errfile.write(u'Failure: %s:%s\n' %(file, filename.decode('cp437')))
songfile=z.open(song)
for l in songfile.readlines():
l=l.decode('utf8')
print(u' |%s\n'%l.strip())
errfile.write(u' |%s\n'%l.strip())
print_exc(3, file=errfile)
continue
print_exc(3)
sys.exit(1)
# continue
# o.finish()
print "OK"
os.unlink(filename)
# o.song.print_song()
if __name__=="__main__":
opensong_import_lots()

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from openlp.plugins.songs.lib.opensongimport import OpenSongImport
from openlp.plugins.songs.lib.manager import SongManager
@ -8,7 +9,7 @@ def test():
# o.finish()
o.song.print_song()
assert o.song.copyright == u'2010 Martin Thompson'
assert o.song.authors == [u'Martin Thompson']
assert o.song.authors == [u'MartiÑ Thómpson']
assert o.song.title == u'Martins Test'
assert o.song.alternate_title == u''
assert o.song.song_number == u'1'