diff -r bfe8ef6e370e -r 57b0c7221dba tests/test-encoding-func.py --- a/tests/test-encoding-func.py Sun Mar 25 16:47:33 2018 +0900 +++ b/tests/test-encoding-func.py Sun Apr 22 11:38:53 2018 +0900 @@ -35,11 +35,32 @@ self.assertTrue(s is encoding.fromlocal(s)) class Utf8bEncodingTest(unittest.TestCase): + def setUp(self): + self.origencoding = encoding.encoding + + def tearDown(self): + encoding.encoding = self.origencoding + def testasciifastpath(self): s = b'\0' * 100 self.assertTrue(s is encoding.toutf8b(s)) self.assertTrue(s is encoding.fromutf8b(s)) + def testlossylatin(self): + encoding.encoding = b'ascii' + s = u'\xc0'.encode('utf-8') + l = encoding.tolocal(s) + self.assertEqual(l, b'?') # lossy + self.assertEqual(s, encoding.toutf8b(l)) # utf8 sequence preserved + + def testlossy0xed(self): + encoding.encoding = b'euc-kr' # U+Dxxx Hangul + s = u'\ud1bc\xc0'.encode('utf-8') + l = encoding.tolocal(s) + self.assertIn(b'\xed', l) + self.assertTrue(l.endswith(b'?')) # lossy + self.assertEqual(s, encoding.toutf8b(l)) # utf8 sequence preserved + if __name__ == '__main__': import silenttestrunner silenttestrunner.main(__name__)