1.1 --- a/tests/iconv.py Mon Dec 12 18:30:40 2016 +0100
1.2 +++ b/tests/iconv.py Mon Dec 12 18:43:29 2016 +0100
1.3 @@ -1,6 +1,6 @@
1.4 # -*- coding: ISO-8859-1 -*-
1.5
1.6 -from posix.iconv import Converter, EINVAL, EILSEQ
1.7 +from posix.iconv import Converter, EILSEQ
1.8
1.9 to_utf8 = Converter("ISO-8859-1", "UTF-8")
1.10 to_utf16 = Converter("ISO-8859-1", "UTF-16")
1.11 @@ -46,6 +46,38 @@
1.12 from_utf8.feed(second) # should have handled the complete input
1.13 print str(from_utf8) # æøå
1.14
1.15 + # Attempt to convert ISO-8859-1 characters as if they were UTF-8.
1.16 +
1.17 + from_utf8.reset()
1.18 +
1.19 + try:
1.20 + from_utf8.feed(iso) # should raise an exception
1.21 + except OSError, exc:
1.22 + if exc.value == EILSEQ:
1.23 + print "Not UTF-8 input:", exc.arg
1.24 + else:
1.25 + print "OSError:", exc.value
1.26 +
1.27 + print str(from_utf8) #
1.28 +
1.29 + # Attempt to convert ISO-8859-1 characters following some UTF-8 ones.
1.30 +
1.31 + to_utf8.reset()
1.32 + to_utf8.feed("ÆØÅ")
1.33 + utf8_2 = str(to_utf8)
1.34 +
1.35 + from_utf8.reset()
1.36 +
1.37 + try:
1.38 + from_utf8.feed(utf8_2 + iso) # should raise an exception
1.39 + except OSError, exc:
1.40 + if exc.value == EILSEQ:
1.41 + print "Not UTF-8 input:", exc.arg
1.42 + else:
1.43 + print "OSError:", exc.value
1.44 +
1.45 + print str(from_utf8) #
1.46 +
1.47 finally:
1.48 to_utf8.close()
1.49 to_utf16.close()