Check whether the choosen encoding requires byte swapping

for this iconv() implementation in the init function.

For encoding: use a byteswapped version of the input if
neccessary.

For decoding: byteswap every piece returned by iconv()
if neccessary (but not those pieces returned from the
callback)

Comment out test_sane() in the test script, because
whether this works depends on whether byte swapping
is neccessary or not (an on Py_UNICODE_SIZE)
This commit is contained in:
Walter Dörwald 2003-01-30 19:55:28 +00:00
parent 2b93c4c708
commit b4ff1113ca
2 changed files with 93 additions and 11 deletions

View file

@ -7,19 +7,23 @@ from StringIO import StringIO
class IconvCodecTest(unittest.TestCase):
if sys.byteorder == 'big':
spam = '\x00s\x00p\x00a\x00m\x00s\x00p\x00a\x00m'
spam = '\x00s\x00p\x00a\x00m' * 2
else:
spam = 's\x00p\x00a\x00m\x00s\x00p\x00a\x00m\x00'
spam = 's\x00p\x00a\x00m\x00' * 2
def test_sane(self):
self.encoder, self.decoder, self.reader, self.writer = \
codecs.lookup(_iconv_codec.internal_encoding)
self.assertEqual(self.decoder(self.spam), (u'spamspam', 16))
self.assertEqual(self.encoder(u'spamspam'), (self.spam, 8))
self.assertEqual(self.reader(StringIO(self.spam)).read(), u'spamspam')
f = StringIO()
self.writer(f).write(u'spamspam')
self.assertEqual(f.getvalue(), self.spam)
# FIXME: Commented out, because it's not clear whether
# the internal encoding choosen requires byte swapping
# for this iconv() implementation.
if False:
self.encoder, self.decoder, self.reader, self.writer = \
codecs.lookup(_iconv_codec.internal_encoding)
self.assertEqual(self.decoder(self.spam), (u'spamspam', 16))
self.assertEqual(self.encoder(u'spamspam'), (self.spam, 8))
self.assertEqual(self.reader(StringIO(self.spam)).read(), u'spamspam')
f = StringIO()
self.writer(f).write(u'spamspam')
self.assertEqual(f.getvalue(), self.spam)
def test_basic_errors(self):
self.encoder, self.decoder, self.reader, self.writer = \