def test_detect_encoding(app): """Test encoding detection.""" f = BytesIO(u'Γκρήκ Στρίνγκ'.encode('utf-8')) initial_position = f.tell() assert detect_encoding(f).lower() == 'utf-8' assert f.tell() == initial_position with patch('cchardet.detect', Exception): assert detect_encoding(f) is None
def test_detect_encoding(app, string, confidence, encoding, detect): """Test encoding detection.""" f = BytesIO(string) initial_position = f.tell() with patch('cchardet.detect') as mock_detect: mock_detect.return_value = { 'encoding': encoding, 'confidence': confidence } assert detect_encoding(f) is detect assert f.tell() == initial_position
def test_detect_encoding_exception(app): f = BytesIO(u'Γκρήκ Στρίνγκ'.encode('utf-8')) with patch('cchardet.detect', Exception): assert detect_encoding(f) is None