Пример #1
0
def test_quick_detect_encoding():
    eq_("ascii", u.quick_detect_encoding(b"qwe").lower())
    ok_(
        u.quick_detect_encoding(u"Versi\xf3n".encode("windows-1252")).lower()
        in ["windows-1252", "windows-1250"]
    )
    eq_("utf-8", u.quick_detect_encoding(u"привет".encode("utf8")).lower())
Пример #2
0
def test_quick_detect_encoding_edge_cases(detect_encoding, cchardet_detect):
    cchardet_detect.return_value = {'encoding': 'ascii'}
    eq_('ascii', u.quick_detect_encoding(b"qwe"))
    cchardet_detect.assert_called_once_with(b"qwe")

    # fallback to detect_encoding
    cchardet_detect.return_value = {}
    detect_encoding.return_value = 'utf-8'
    eq_('utf-8', u.quick_detect_encoding(b"qwe"))

    # exception
    detect_encoding.reset_mock()
    cchardet_detect.side_effect = Exception()
    detect_encoding.return_value = 'utf-8'
    eq_('utf-8', u.quick_detect_encoding(b"qwe"))
    ok_(detect_encoding.called)
Пример #3
0
def test_quick_detect_encoding_edge_cases(detect_encoding, cchardet_detect):
    cchardet_detect.return_value = {'encoding': 'ascii'}
    eq_('ascii', u.quick_detect_encoding(b"qwe"))
    cchardet_detect.assert_called_once_with(b"qwe")

    # fallback to detect_encoding
    cchardet_detect.return_value = {}
    detect_encoding.return_value = 'utf-8'
    eq_('utf-8', u.quick_detect_encoding(b"qwe"))

    # exception
    detect_encoding.reset_mock()
    cchardet_detect.side_effect = Exception()
    detect_encoding.return_value = 'utf-8'
    eq_('utf-8', u.quick_detect_encoding(b"qwe"))
    ok_(detect_encoding.called)
Пример #4
0
def test_quick_detect_encoding():
    eq_('ascii', u.quick_detect_encoding(b'qwe').lower())
    ok_(
        u.quick_detect_encoding(u'Versi\xf3n'.encode('windows-1252')).lower()
        in ['windows-1252', 'windows-1250'])
    eq_('utf-8', u.quick_detect_encoding(u'привет'.encode('utf8')).lower())
Пример #5
0
def test_quick_detect_encoding():
    eq_('ascii', u.quick_detect_encoding(b'qwe').lower())
    ok_(u.quick_detect_encoding(
        u'Versi\xf3n'.encode('windows-1252')).lower() in [
            'windows-1252', 'windows-1250'])
    eq_('utf-8', u.quick_detect_encoding(u'привет'.encode('utf8')).lower())
Пример #6
0
def test_quick_detect_encoding():
    eq_ ('ascii', u.quick_detect_encoding('qwe').lower())
    eq_ ('windows-1252', u.quick_detect_encoding('Versi\xf3n').lower())
    eq_ ('utf-8', u.quick_detect_encoding('привет').lower())