diff options
Diffstat (limited to 'test/test_tools/test_himo.py')
-rw-r--r-- | test/test_tools/test_himo.py | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/test/test_tools/test_himo.py b/test/test_tools/test_himo.py new file mode 100644 index 0000000..cb58ca5 --- /dev/null +++ b/test/test_tools/test_himo.py | |||
@@ -0,0 +1,107 @@ | |||
1 | import sys | ||
2 | import os | ||
3 | import unittest | ||
4 | path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')) | ||
5 | sys.path.append(path) | ||
6 | from dodai.tools.himo import String2Himo | ||
7 | from dodai.tools.himo import Himo | ||
8 | from dodai.tools.himo import HimoAsciiError | ||
9 | from decimal import Decimal as D | ||
10 | |||
11 | class TestString2Himo(unittest.TestCase): | ||
12 | |||
13 | def setUp(self): | ||
14 | self.string_to_himo_one = String2Himo() | ||
15 | self.string_to_himo_two = String2Himo('unicode_escape') | ||
16 | |||
17 | def test_regular_string_one(self): | ||
18 | obj = self.string_to_himo_one(str('abcd')) | ||
19 | self.assertTrue(isinstance(obj, Himo)) | ||
20 | |||
21 | def test_regular_string_two(self): | ||
22 | test = str('abcd') | ||
23 | obj = self.string_to_himo_one(test) | ||
24 | self.assertTrue(obj == test) | ||
25 | |||
26 | def test_regular_string_three(self): | ||
27 | obj = self.string_to_himo_two(str('abcd')) | ||
28 | self.assertTrue(isinstance(obj, Himo)) | ||
29 | |||
30 | def test_regular_string_four(self): | ||
31 | test = str('abcd') | ||
32 | obj = self.string_to_himo_two(test) | ||
33 | self.assertTrue(obj == test) | ||
34 | |||
35 | def test_regular_string_five(self): | ||
36 | test = 1 | ||
37 | obj = self.string_to_himo_two(test) | ||
38 | self.assertEqual(int(obj), test) | ||
39 | |||
40 | def test_decode_html(self): | ||
41 | test = u'\u4e5d\xf2\xe5\xe9' | ||
42 | obj = self.string_to_himo_one(u'九òåé') | ||
43 | self.assertEqual(test, obj) | ||
44 | |||
45 | def test_decode_chardet(self): | ||
46 | # Korean Text in the EUC-KR character set | ||
47 | kor = '\xb4\xe7\xbd\xc5\xc0\xcc \xc3\xa3\xb4\xc2 \xb8\xf0\xb5\xe7 '\ | ||
48 | '\xbd\xba\xc5\xb8\xc0\xcf, \xbf\xc1\xbc\xc7' | ||
49 | test = '\ub2f9\uc2e0\uc774 \ucc3e\ub294 \ubaa8\ub4e0 '\ | ||
50 | '\uc2a4\ud0c0\uc77c, \uc625\uc158'.decode('unicode_escape') | ||
51 | obj = self.string_to_himo_one(kor) | ||
52 | self.assertEqual(obj, test) | ||
53 | |||
54 | def test_html_decode_one(self): | ||
55 | # Korean Text | ||
56 | kor = '당신이 찾는 모든 '\ | ||
57 | '스타일, 옥션& foo' | ||
58 | test = u'\ub2f9\uc2e0\uc774 \ucc3e\ub294 \ubaa8\ub4e0 '\ | ||
59 | u'\uc2a4\ud0c0\uc77c, \uc625\uc158& foo' | ||
60 | obj = self.string_to_himo_one(kor) | ||
61 | self.assertEqual(obj, test) | ||
62 | |||
63 | def test_html_decode_two(self): | ||
64 | kor = '&ppe;' | ||
65 | obj = self.string_to_himo_one(kor) | ||
66 | self.assertEqual(obj, kor) | ||
67 | |||
68 | |||
69 | class TestHimo(unittest.TestCase): | ||
70 | |||
71 | def setUp(self): | ||
72 | # "Elephants are our brothers" in Japanese. This line comes from | ||
73 | # an episode of a old Japanese TV show called "Koko Ga Hen Da Yo, | ||
74 | # Nihonjin" http://en.wikipedia.org/wiki/Koko_ga_hen_da_yo,_nihonjin | ||
75 | # This line came from an African native who spoke Japanese fluently | ||
76 | self.jp = u'\u8c61\u306f\u79c1\u305f\u3061\u306e\u5144\u5f1f'\ | ||
77 | u'\u3067\u3059' | ||
78 | self.jp_html = u'象は私たちの'\ | ||
79 | u'兄弟です' | ||
80 | |||
81 | def test_html(self): | ||
82 | obj = Himo(self.jp) | ||
83 | test = obj.html() | ||
84 | self.assertEqual(test, self.jp_html) | ||
85 | |||
86 | def test_decimal(self): | ||
87 | obj = Himo('23.55') | ||
88 | obj = obj.decimal() | ||
89 | self.assertTrue(isinstance(obj, D)) | ||
90 | self.assertEqual(obj, D('23.55')) | ||
91 | |||
92 | def test_ascii_one(self): | ||
93 | # "Elephants live in Africa" in spanish | ||
94 | obj = Himo(u'Los elefantes viven en \xc1frica') | ||
95 | test = u'Los elefantes viven en Africa' | ||
96 | self.assertEqual(obj.ascii(), test) | ||
97 | |||
98 | def test_ascii_two(self): | ||
99 | # "Elephants are our brothers" in French | ||
100 | obj = Himo(u'Les \xe9l\xe9phants sont nos fr\xe8res \xa9') | ||
101 | test = u'Les elephants sont nos freres (C)' | ||
102 | self.assertEqual(obj.ascii(), test) | ||
103 | |||
104 | def test_ascii_three(self): | ||
105 | |||
106 | obj = Himo(self.jp) | ||
107 | self.failUnlessRaises(HimoAsciiError, obj.ascii) | ||