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
|
import apsw
|
||||||
from polyglot.builtins import (iteritems, itervalues,
|
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 import isbytestring, force_unicode, prints, as_unicode
|
||||||
from calibre.constants import (iswindows, filesystem_encoding,
|
from calibre.constants import (iswindows, filesystem_encoding,
|
||||||
@ -1745,6 +1745,8 @@ class DB(object):
|
|||||||
|
|
||||||
def set_conversion_options(self, options, fmt):
|
def set_conversion_options(self, options, fmt):
|
||||||
def map_data(x):
|
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 = x.encode('utf-8') if isinstance(x, unicode_type) else x
|
||||||
x = pickle_binary_string(x)
|
x = pickle_binary_string(x)
|
||||||
if not ispy3:
|
if not ispy3:
|
||||||
|
@ -298,9 +298,15 @@ class LegacyTest(BaseTest):
|
|||||||
def test_legacy_conversion_options(self): # {{{
|
def test_legacy_conversion_options(self): # {{{
|
||||||
'Test conversion options API'
|
'Test conversion options API'
|
||||||
ndb = self.init_legacy()
|
ndb = self.init_legacy()
|
||||||
db = self.init_old()
|
db = self.init_old()
|
||||||
all_ids = ndb.new_api.all_book_ids()
|
all_ids = ndb.new_api.all_book_ids()
|
||||||
op1 = {'xx':'yy'}
|
op1 = {'xx': 'yy'}
|
||||||
|
|
||||||
|
def decode(x):
|
||||||
|
if isinstance(x, bytes):
|
||||||
|
x = x.decode('utf-8')
|
||||||
|
return x
|
||||||
|
|
||||||
for x in (
|
for x in (
|
||||||
('has_conversion_options', all_ids),
|
('has_conversion_options', all_ids),
|
||||||
('conversion_options', 1, 'PIPE'),
|
('conversion_options', 1, 'PIPE'),
|
||||||
@ -311,8 +317,10 @@ class LegacyTest(BaseTest):
|
|||||||
('has_conversion_options', all_ids),
|
('has_conversion_options', all_ids),
|
||||||
):
|
):
|
||||||
meth, args = x[0], x[1:]
|
meth, args = x[0], x[1:]
|
||||||
self.assertEqual((getattr(db, meth)(*args)), (getattr(ndb, meth)(*args)),
|
self.assertEqual(
|
||||||
'The method: %s() returned different results for argument %s' % (meth, args))
|
decode(getattr(db, meth)(*args)), decode(getattr(ndb, meth)(*args)),
|
||||||
|
'The method: %s() returned different results for argument %s' % (meth, args)
|
||||||
|
)
|
||||||
db.close()
|
db.close()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user