mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: port legacy conversion options test
This commit is contained in:
parent
3e68346e4e
commit
a5324474d8
@ -13,7 +13,7 @@ from functools import partial
|
||||
|
||||
import apsw
|
||||
from polyglot.builtins import (iteritems, itervalues,
|
||||
unicode_type, reraise, string_or_bytes, cmp)
|
||||
unicode_type, reraise, string_or_bytes, cmp, native_string_type)
|
||||
|
||||
from calibre import isbytestring, force_unicode, prints, as_unicode
|
||||
from calibre.constants import (iswindows, filesystem_encoding,
|
||||
@ -1745,6 +1745,8 @@ class DB(object):
|
||||
|
||||
def set_conversion_options(self, options, fmt):
|
||||
def map_data(x):
|
||||
if not isinstance(x, string_or_bytes):
|
||||
x = native_string_type(x)
|
||||
x = x.encode('utf-8') if isinstance(x, unicode_type) else x
|
||||
x = pickle_binary_string(x)
|
||||
if not ispy3:
|
||||
|
@ -301,6 +301,12 @@ class LegacyTest(BaseTest):
|
||||
db = self.init_old()
|
||||
all_ids = ndb.new_api.all_book_ids()
|
||||
op1 = {'xx': 'yy'}
|
||||
|
||||
def decode(x):
|
||||
if isinstance(x, bytes):
|
||||
x = x.decode('utf-8')
|
||||
return x
|
||||
|
||||
for x in (
|
||||
('has_conversion_options', all_ids),
|
||||
('conversion_options', 1, 'PIPE'),
|
||||
@ -311,8 +317,10 @@ class LegacyTest(BaseTest):
|
||||
('has_conversion_options', all_ids),
|
||||
):
|
||||
meth, args = x[0], x[1:]
|
||||
self.assertEqual((getattr(db, meth)(*args)), (getattr(ndb, meth)(*args)),
|
||||
'The method: %s() returned different results for argument %s' % (meth, args))
|
||||
self.assertEqual(
|
||||
decode(getattr(db, meth)(*args)), decode(getattr(ndb, meth)(*args)),
|
||||
'The method: %s() returned different results for argument %s' % (meth, args)
|
||||
)
|
||||
db.close()
|
||||
# }}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user