This commit is contained in:
PyYoshi 2016-10-17 11:05:27 +09:00
parent fba4c216ee
commit 082910859b

View file

@ -1,56 +1,19 @@
#!/usr/bin/env python #!/usr/bin/env python
# coding: utf-8 # coding: utf-8
# nosetests --nocapture tests.py
from nose.tools import eq_ from nose.tools import eq_
# http://docs.python.org/library/codecs.html
# https://bitbucket.org/medoc/uchardet-enhanced/src/85fc77c3e058/libcharsetdetect/README.md
# Support codecs
# Big5
# EUC-JP
# EUC-KR
# GB18030
# gb18030
# HZ-GB-2312
# IBM855
# IBM866
# ISO-2022-CN
# ISO-2022-JP
# ISO-2022-KR
# ISO-8859-2
# ISO-8859-5
# ISO-8859-7
# ISO-8859-8
# KOI8-R
# Shift_JIS
# TIS-620
# UTF-8
# UTF-16BE
# UTF-16LE
# UTF-32BE
# UTF-32LE
# windows-1250
# windows-1251
# windows-1252
# windows-1253
# windows-1255
# x-euc-tw
# X-ISO-10646-UCS-4-2143
# X-ISO-10646-UCS-4-3412
# x-mac-cyrillic
import cchardet import cchardet
class TestCchardet():
class TestCchardet():
def test_detect_bg_iso88595(self): def test_detect_bg_iso88595(self):
encoding = "ISO-8859-5" encoding = "ISO-8859-5"
path = r"testdata/bg/ISO-8859-5/wikitop_bg_ISO-8859-5.txt" path = r"testdata/bg/ISO-8859-5/wikitop_bg_ISO-8859-5.txt"
with open(path, 'rb') as f: with open(path, 'rb') as f:
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_bg_utf8(self): def test_detect_bg_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -59,7 +22,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_bg_windows1251(self): def test_detect_bg_windows1251(self):
encoding = "WINDOWS-1251" encoding = "WINDOWS-1251"
@ -68,7 +31,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_cz_iso88592(self): def test_detect_cz_iso88592(self):
encoding = "ISO-8859-2" encoding = "ISO-8859-2"
@ -77,7 +40,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_cz_utf8(self): def test_detect_cz_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -86,7 +49,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_de_utf8(self): def test_detect_de_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -95,7 +58,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_de_windows1252(self): def test_detect_de_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -104,7 +67,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_dk_utf8(self): def test_detect_dk_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -113,7 +76,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_dk_windows1252(self): def test_detect_dk_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -122,7 +85,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_el_iso88597(self): def test_detect_el_iso88597(self):
encoding = "ISO-8859-7" encoding = "ISO-8859-7"
@ -131,7 +94,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_el_utf8(self): def test_detect_el_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -140,7 +103,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_en_utf8(self): def test_detect_en_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -149,7 +112,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_en_windows1252(self): def test_detect_en_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -158,7 +121,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_es_utf8(self): def test_detect_es_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -167,7 +130,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_es_windows1252(self): def test_detect_es_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -176,7 +139,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_fi_utf8(self): def test_detect_fi_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -185,7 +148,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_fi_windows1252(self): def test_detect_fi_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -194,7 +157,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_fr_utf8(self): def test_detect_fr_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -203,7 +166,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_fr_windows1252(self): def test_detect_fr_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -212,7 +175,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_he_utf8(self): def test_detect_he_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -221,7 +184,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_he_windows1255(self): def test_detect_he_windows1255(self):
encoding = "WINDOWS-1255" encoding = "WINDOWS-1255"
@ -230,7 +193,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_hu_utf8(self): def test_detect_hu_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -239,7 +202,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_hu_iso55892(self): def test_detect_hu_iso55892(self):
encoding = "ISO-8859-2" encoding = "ISO-8859-2"
@ -248,7 +211,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_it_utf8(self): def test_detect_it_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -257,7 +220,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_it_windows1252(self): def test_detect_it_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -266,7 +229,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_nl_utf8(self): def test_detect_nl_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -275,7 +238,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_nl_windows1252(self): def test_detect_nl_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -284,7 +247,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_no_utf8(self): def test_detect_no_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -293,7 +256,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_no_windows1252(self): def test_detect_no_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -302,7 +265,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_pl_utf8(self): def test_detect_pl_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -311,7 +274,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_pl_iso88592(self): def test_detect_pl_iso88592(self):
encoding = "ISO-8859-2" encoding = "ISO-8859-2"
@ -320,7 +283,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_pt_utf8(self): def test_detect_pt_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -329,7 +292,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_pt_windows1252(self): def test_detect_pt_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -338,7 +301,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_ru_utf8(self): def test_detect_ru_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -347,7 +310,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_ru_windows1251(self): def test_detect_ru_windows1251(self):
encoding = "WINDOWS-1251" encoding = "WINDOWS-1251"
@ -356,7 +319,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_ru_ibm855(self): def test_detect_ru_ibm855(self):
encoding = "IBM855" encoding = "IBM855"
@ -365,7 +328,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_ru_koi8r(self): def test_detect_ru_koi8r(self):
encoding = "KOI8-R" encoding = "KOI8-R"
@ -374,7 +337,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_ru_maccyrillic(self): def test_detect_ru_maccyrillic(self):
encoding = "MAC-CYRILLIC" encoding = "MAC-CYRILLIC"
@ -383,7 +346,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_se_utf8(self): def test_detect_se_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -392,7 +355,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_se_windows1252(self): def test_detect_se_windows1252(self):
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
@ -401,7 +364,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_th_utf8(self): def test_detect_th_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -410,7 +373,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_th_tis620_1(self): def test_detect_th_tis620_1(self):
encoding = "TIS-620" encoding = "TIS-620"
@ -419,7 +382,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_th_tis620_2(self): def test_detect_th_tis620_2(self):
encoding = "TIS-620" encoding = "TIS-620"
@ -428,7 +391,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_tr_utf8(self): def test_detect_tr_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -437,7 +400,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_tr_iso88599(self): def test_detect_tr_iso88599(self):
encoding = "ISO-8859-9" encoding = "ISO-8859-9"
@ -446,7 +409,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_zh_utf8(self): def test_detect_zh_utf8(self):
encoding = "UTF-8" encoding = "UTF-8"
@ -455,7 +418,7 @@ class TestCchardet():
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
def test_detect_zh_gb18030(self): def test_detect_zh_gb18030(self):
encoding = "GB18030" encoding = "GB18030"
@ -463,7 +426,8 @@ class TestCchardet():
with open(path, 'rb') as f: with open(path, 'rb') as f:
msg = f.read() msg = f.read()
detected_encoding = cchardet.detect(msg) detected_encoding = cchardet.detect(msg)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(), detected_encoding['encoding'].lower())
class TestCchardetSpeed(): class TestCchardetSpeed():
def test_speed(self): def test_speed(self):
@ -484,18 +448,17 @@ class TestCchardetSpeed():
start_chardet = time.time() start_chardet = time.time()
chardet.detect(msg) chardet.detect(msg)
result_chardet += (time.time() - start_chardet) result_chardet += (time.time() - start_chardet)
print('chardet:',1/(result_chardet/do_times), 'call(s)/s') print('chardet:', 1 / (result_chardet / do_times), 'call(s)/s')
# Test cchardet # Test cchardet
result_cchardet = 0 result_cchardet = 0
for i in range(do_times): for i in range(do_times):
start_cchardet = time.time() start_cchardet = time.time()
cchardet.detect(msg) cchardet.detect(msg)
result_cchardet += (time.time() - start_cchardet) result_cchardet += (time.time() - start_cchardet)
print('cchardet:',1/(result_cchardet/do_times), 'call(s)/s') print('cchardet:', 1 / (result_cchardet / do_times), 'call(s)/s')
class TestDetector(): class TestDetector():
encodings_map = { encodings_map = {
r"testdata/bg/ISO-8859-5/wikitop_bg_ISO-8859-5.txt": "ISO-8859-5", r"testdata/bg/ISO-8859-5/wikitop_bg_ISO-8859-5.txt": "ISO-8859-5",
r"testdata/bg/UTF-8/wikitop_bg_UTF-8.txt": "UTF-8", r"testdata/bg/UTF-8/wikitop_bg_UTF-8.txt": "UTF-8",