def test_guess_encoding_and_decode(self): for header in DECODED_HEADERS: try: encoding.guess_encoding_and_decode('ascii', header.encode('utf-8')) except encoding.EncodingError: pass
def test_guess_encoding_and_decode_unicode_error(): data = Mock() data.__str__ = Mock() data.__str__.return_value = u"\0\0" data.decode.side_effect = raises_UnicodeError encoding.guess_encoding_and_decode("ascii", data)
def test_guess_encoding_fails_completely(): chardet.detect.return_value = {'encoding': None, 'confidence': 0.0} encoding.guess_encoding_and_decode('ascii', 'some data', errors='strict')
def test_guess_encoding_and_decode(): for header in DECODED_HEADERS: try: encoding.guess_encoding_and_decode('ascii', header.encode('utf-8')) except encoding.EncodingError: pass
def test_guess_encoding_and_decode_unicode_error(self, detect_mock): data = "testß".encode("latin-1") detect_mock.return_value = {"confidence": 0.99, "encoding": "utf-8"} with self.assertRaises(encoding.EncodingError): encoding.guess_encoding_and_decode("ascii", data)
def test_guess_encoding_fails_completely(self): chardet.detect.return_value = {'encoding': None, 'confidence': 0.0} with self.assertRaises(encoding.EncodingError): encoding.guess_encoding_and_decode('ascii', 'some data', errors='strict')
def test_guess_encoding_and_decode_unicode_error(detect_mock): data = u"testß".encode("latin-1") detect_mock.return_value = {"confidence": 0.99, "encoding": "utf-8"} encoding.guess_encoding_and_decode("ascii", data)
def test_guess_encoding_fails_completely(): chardet.detect.return_value = {"encoding": None, "confidence": 0.0} encoding.guess_encoding_and_decode("ascii", "some data", errors="strict")