44
55import unittest
66from argparse import ArgumentError
7- from types import ModuleType
87
98from pythainlp import __main__ , cli
9+ from pythainlp .cli .data import App as DataApp
10+ from pythainlp .cli .soundex import App as SoundexApp
11+ from pythainlp .cli .tag import App as TagApp
12+ from pythainlp .cli .tokenize import App as TokenizeApp
1013
1114
1215class CliTestCase (unittest .TestCase ):
@@ -26,68 +29,40 @@ def test_cli_main(self):
2629
2730 self .assertIsNone (__main__ .main (["thainlp" , "data" , "path" ]))
2831
29- def test_cli_benchmark (self ):
30- self .assertIsInstance (getattr (cli , "benchmark" ), ModuleType )
31-
32- with self .assertRaises (SystemExit ) as ex :
33- cli .data .App (["thainlp" , "benchmark" ])
34- self .assertEqual (ex .exception .code , 2 )
35-
36- self .assertIsNotNone (
37- cli .benchmark .App (
38- [
39- "thainlp" ,
40- "benchmark" ,
41- "word-tokenization" ,
42- "--input-file" ,
43- "./tests/data/input.txt" ,
44- "--test-file" ,
45- "./tests/data/test.txt" ,
46- "--save-details" ,
47- ]
48- )
49- )
50-
5132 def test_cli_data (self ):
52- self .assertIsInstance ( getattr (cli , "data" ), ModuleType )
33+ self .assertTrue ( hasattr (cli , "data" ))
5334
5435 with self .assertRaises (SystemExit ) as ex :
55- cli . data . App (["thainlp" , "data" ])
36+ DataApp (["thainlp" , "data" ])
5637 self .assertEqual (ex .exception .code , 2 )
5738
58- self .assertIsNotNone (cli .data .App (["thainlp" , "data" , "catalog" ]))
59- self .assertIsNotNone (cli .data .App (["thainlp" , "data" , "path" ]))
60- self .assertIsNotNone (cli .data .App (["thainlp" , "data" , "get" , "test" ]))
61- self .assertIsNotNone (cli .data .App (["thainlp" , "data" , "info" , "test" ]))
62- self .assertIsNotNone (cli .data .App (["thainlp" , "data" , "rm" , "test" ]))
63- self .assertIsNotNone (
64- cli .data .App (["thainlp" , "data" , "get" , "NOT_EXIST" ])
65- )
66- self .assertIsNotNone (
67- cli .data .App (["thainlp" , "data" , "info" , "NOT_EXIST" ])
68- )
69- self .assertIsNotNone (
70- cli .data .App (["thainlp" , "data" , "rm" , "NOT_EXIST" ])
71- )
39+ self .assertIsNotNone (DataApp (["thainlp" , "data" , "catalog" ]))
40+ self .assertIsNotNone (DataApp (["thainlp" , "data" , "path" ]))
41+ self .assertIsNotNone (DataApp (["thainlp" , "data" , "get" , "test" ]))
42+ self .assertIsNotNone (DataApp (["thainlp" , "data" , "info" , "test" ]))
43+ self .assertIsNotNone (DataApp (["thainlp" , "data" , "rm" , "test" ]))
44+ self .assertIsNotNone (DataApp (["thainlp" , "data" , "get" , "NOT_EXIST" ]))
45+ self .assertIsNotNone (DataApp (["thainlp" , "data" , "info" , "NOT_EXIST" ]))
46+ self .assertIsNotNone (DataApp (["thainlp" , "data" , "rm" , "NOT_EXIST" ]))
7247
7348 def test_cli_soundex (self ):
74- self .assertIsInstance ( getattr (cli , "soundex" ), ModuleType )
49+ self .assertTrue ( hasattr (cli , "soundex" ))
7550
7651 with self .assertRaises (SystemExit ) as ex :
77- cli . data . App (["thainlp" , "soundex" ])
52+ DataApp (["thainlp" , "soundex" ])
7853 self .assertEqual (ex .exception .code , 2 )
7954
80- self .assertIsNotNone (cli . soundex . App (["thainlp" , "soundex" , "ทดสอบ" ]))
55+ self .assertIsNotNone (SoundexApp (["thainlp" , "soundex" , "ทดสอบ" ]))
8156
8257 def test_cli_tag (self ):
83- self .assertIsInstance ( getattr (cli , "tag" ), ModuleType )
58+ self .assertTrue ( hasattr (cli , "tag" ))
8459
8560 with self .assertRaises (SystemExit ) as ex :
86- cli . data . App (["thainlp" , "tag" ])
61+ DataApp (["thainlp" , "tag" ])
8762 self .assertEqual (ex .exception .code , 2 )
8863
8964 self .assertIsNotNone (
90- cli . tag . App (
65+ TagApp (
9166 [
9267 "thainlp" ,
9368 "tag" ,
@@ -99,7 +74,7 @@ def test_cli_tag(self):
9974 )
10075 )
10176 self .assertIsNotNone (
102- cli . tag . App (
77+ TagApp (
10378 [
10479 "thainlp" ,
10580 "tag" ,
@@ -112,17 +87,17 @@ def test_cli_tag(self):
11287 )
11388
11489 def test_cli_tokenize (self ):
115- self .assertIsInstance ( getattr (cli , "tokenize" ), ModuleType )
90+ self .assertTrue ( hasattr (cli , "tokenize" ))
11691
11792 with self .assertRaises (SystemExit ) as ex :
118- cli . data . App (["thainlp" , "tokenize" ])
93+ DataApp (["thainlp" , "tokenize" ])
11994 self .assertEqual (ex .exception .code , 2 )
12095
12196 self .assertIsNotNone (
122- cli . tokenize . App (["thainlp" , "tokenize" , "NOT_EXIST" , "ไม่มีอยู่ จริง" ])
97+ TokenizeApp (["thainlp" , "tokenize" , "NOT_EXIST" , "ไม่มีอยู่ จริง" ])
12398 )
12499 self .assertIsNotNone (
125- cli . tokenize . App (
100+ TokenizeApp (
126101 [
127102 "thainlp" ,
128103 "tokenize" ,
@@ -134,7 +109,7 @@ def test_cli_tokenize(self):
134109 )
135110 )
136111 self .assertIsNotNone (
137- cli . tokenize . App (
112+ TokenizeApp (
138113 [
139114 "thainlp" ,
140115 "tokenize" ,
@@ -147,7 +122,7 @@ def test_cli_tokenize(self):
147122 )
148123 )
149124 self .assertIsNotNone (
150- cli . tokenize . App (
125+ TokenizeApp (
151126 [
152127 "thainlp" ,
153128 "tokenize" ,
@@ -161,19 +136,3 @@ def test_cli_tokenize(self):
161136 ]
162137 )
163138 )
164- self .assertIsNotNone (
165- cli .tokenize .App (
166- [
167- "thainlp" ,
168- "tokenize" ,
169- "sent" ,
170- "-s" ,
171- "|" ,
172- (
173- "ถ้าฉันยิงกระต่ายได้ ฉันก็ยิงฟาสซิสต์ได้"
174- "กระสุนสำหรับสมองของคุณวันนี้"
175- "แต่คุณก็จะลืมมันไปทั้งหมดอีกครั้ง"
176- ),
177- ]
178- )
179- )
0 commit comments