Test for ability to open a DB in an arbitrary Unicode path with a Unicode name.
And fix a couple of bugs that made the test fail.
This commit is contained in:
parent
9eeadca892
commit
7dfb2e016f
@ -37,6 +37,7 @@ from __future__ import print_function
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import io
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from urllib2 import urlopen, url2pathname
|
from urllib2 import urlopen, url2pathname
|
||||||
@ -244,7 +245,7 @@ class CLIDbManager(object):
|
|||||||
dirpath = os.path.join(dbdir, dpath)
|
dirpath = os.path.join(dbdir, dpath)
|
||||||
path_name = os.path.join(dirpath, NAME_FILE)
|
path_name = os.path.join(dirpath, NAME_FILE)
|
||||||
if os.path.isfile(path_name):
|
if os.path.isfile(path_name):
|
||||||
file = open(path_name)
|
file = io.open(path_name, 'r', encoding='utf8')
|
||||||
name = file.readline().strip()
|
name = file.readline().strip()
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
@ -302,8 +303,8 @@ class CLIDbManager(object):
|
|||||||
if title is None:
|
if title is None:
|
||||||
name_list = [ name[0] for name in self.current_names ]
|
name_list = [ name[0] for name in self.current_names ]
|
||||||
title = find_next_db_name(name_list)
|
title = find_next_db_name(name_list)
|
||||||
|
|
||||||
name_file = open(path_name, "w")
|
name_file = io.open(path_name, "w", encoding='utf8')
|
||||||
name_file.write(title)
|
name_file.write(title)
|
||||||
name_file.close()
|
name_file.close()
|
||||||
|
|
||||||
@ -412,10 +413,10 @@ class CLIDbManager(object):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
filepath = conv_to_unicode(filepath, 'utf8')
|
filepath = conv_to_unicode(filepath, 'utf8')
|
||||||
name_file = open(filepath, "r")
|
name_file = io.open(filepath, "r", encoding='utf8')
|
||||||
old_text=name_file.read()
|
old_text=name_file.read()
|
||||||
name_file.close()
|
name_file.close()
|
||||||
name_file = open(filepath, "w")
|
name_file = io.open(filepath, "w", encoding='utf8')
|
||||||
name_file.write(new_text)
|
name_file.write(new_text)
|
||||||
name_file.close()
|
name_file.close()
|
||||||
except (OSError, IOError) as msg:
|
except (OSError, IOError) as msg:
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
import re
|
import re
|
||||||
|
import io
|
||||||
|
|
||||||
test_ged = """0 HEAD
|
test_ged = """0 HEAD
|
||||||
1 SOUR min1r.ged min 1-rec
|
1 SOUR min1r.ged min 1-rec
|
||||||
@ -102,6 +103,40 @@ class Test(unittest.TestCase):
|
|||||||
for fn in bogofiles:
|
for fn in bogofiles:
|
||||||
self.assertFalse(os.path.exists(fn))
|
self.assertFalse(os.path.exists(fn))
|
||||||
|
|
||||||
|
class UnicodeTest(unittest.TestCase):
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.version_info[0] < 3 and sys.platform == 'win32')
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
from gramps.cli.clidbman import CLIDbManager
|
||||||
|
from gramps.gen.config import set as setconfig
|
||||||
|
from gramps.gen.dbstate import DbState
|
||||||
|
self.newpath = os.path.join(os.path.dirname(__file__),
|
||||||
|
u'\u0393\u03c1\u03b1\u03bc\u03c3\u03c0')
|
||||||
|
self.newtitle = u'Gr\u00e4mps T\u00e9st'
|
||||||
|
os.makedirs(self.newpath)
|
||||||
|
setconfig('behavior.database-path', self.newpath)
|
||||||
|
self.cli = CLIDbManager(DbState())
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
for (dirpath, dirnames, filenames) in os.walk(self.newpath, False):
|
||||||
|
for afile in filenames:
|
||||||
|
os.remove(os.path.join(dirpath, afile))
|
||||||
|
for adir in dirnames:
|
||||||
|
os.rmdir(os.path.join(dirpath, adir))
|
||||||
|
os.rmdir(self.newpath)
|
||||||
|
|
||||||
|
# Test that clidbman will open files in a path containing
|
||||||
|
# arbitrary Unicode characters.
|
||||||
|
def test4_arbitrary_uncode_path(self):
|
||||||
|
(dbpath, title) = self.cli.create_new_db_cli(self.newtitle)
|
||||||
|
|
||||||
|
self.assertEquals(self.newpath, os.path.dirname(dbpath),
|
||||||
|
"Compare paths %s and %s" % (repr(self.newpath),
|
||||||
|
repr(dbpath)))
|
||||||
|
self.assertEquals(self.newtitle, title, "Compare titles %s and %s" %
|
||||||
|
(repr(self.newtitle), repr(title)))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -95,6 +95,10 @@ _ = glocale.translation.gettext
|
|||||||
|
|
||||||
_LOG = logging.getLogger(DBLOGNAME)
|
_LOG = logging.getLogger(DBLOGNAME)
|
||||||
LOG = logging.getLogger(".citation")
|
LOG = logging.getLogger(".citation")
|
||||||
|
#_LOG.setLevel(logging.DEBUG)
|
||||||
|
#_hdlr = logging.StreamHandler()
|
||||||
|
#_hdlr.setFormatter(logging.Formatter(fmt="%(name)s.%(levelname)s: %(message)s"))
|
||||||
|
#_LOG.addHandler(_hdlr)
|
||||||
_MINVERSION = 9
|
_MINVERSION = 9
|
||||||
_DBVERSION = 17
|
_DBVERSION = 17
|
||||||
|
|
||||||
@ -221,7 +225,7 @@ def _encode(path):
|
|||||||
"""
|
"""
|
||||||
Conditionally return the unicode string encoded to sys.filesystem.encoding
|
Conditionally return the unicode string encoded to sys.filesystem.encoding
|
||||||
"""
|
"""
|
||||||
if not (isinstance(path, UNITYPE) and win() and sys.version_info[0] < 3):
|
if not (isinstance(path, UNITYPE) and sys.version_info[0] < 3):
|
||||||
_LOG.debug("Didn't Encode %s", repr(path))
|
_LOG.debug("Didn't Encode %s", repr(path))
|
||||||
return path
|
return path
|
||||||
_LOG.debug("Encoding %s", repr(path))
|
_LOG.debug("Encoding %s", repr(path))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user