def _test_bom(self, bom, encoding): test_string = 'Zażółć gęślą jaźń' test_io = io.BytesIO(bom + test_string.encode(encoding)) detected_encoding = utils.try_detect_encoding(test_io) self.assertEqual(codecs.lookup(detected_encoding), codecs.lookup(encoding)) decoded = codecs.getreader(detected_encoding)(test_io).read() self.assertEqual(decoded, test_string)
def _test_magic(self, encoding): test_string = 'Zażółć gęślą jaźń' magic = '; -*- coding: {} -*-\n'.format(encoding) # Magic comment must be included in resulting stream! test_string = magic + test_string test_io = io.BytesIO(test_string.encode(encoding)) detected_encoding = utils.try_detect_encoding(test_io) self.assertEqual(codecs.lookup(detected_encoding), codecs.lookup(encoding)) decoded = codecs.getreader(detected_encoding)(test_io).read() self.assertEqual(decoded, test_string)