44import unittest
55from collections import Counter
66
7+ from pythainlp .tokenize import word_tokenize
78from pythainlp .util import (
89 arabic_digit_to_thai_digit ,
910 bahttext ,
1011 collate ,
1112 countthai ,
1213 delete_tone ,
14+ deletetone ,
1315 digit_to_text ,
1416 eng_to_thai ,
1517 find_keyword ,
2527 text_to_thai_digit ,
2628 thai_digit_to_arabic_digit ,
2729 thai_strftime ,
30+ thai_time ,
2831 thai_to_eng ,
32+ thaicheck ,
2933 thaiword_to_num ,
30- thai_time ,
3134)
32- from pythainlp .tokenize import word_tokenize
3335
3436
3537class TestUtilPackage (unittest .TestCase ):
@@ -144,6 +146,12 @@ def test_date(self):
144146
145147 def test_thai_strftime (self ):
146148 date = datetime .datetime (1976 , 10 , 6 , 1 , 40 )
149+ self .assertEqual (thai_strftime (date , "%d" ), "06" )
150+ self .assertEqual (thai_strftime (date , "%-d" ), "6" )
151+ self .assertEqual (thai_strftime (date , "%-d" , True ), "๖" )
152+ self .assertEqual (thai_strftime (date , "%%" ), "%" )
153+ self .assertEqual (thai_strftime (date , "%-" ), "-" )
154+ self .assertEqual (thai_strftime (date , "%P" ), "P" )
147155 self .assertEqual (thai_strftime (date , "%c" ), "พ 6 ต.ค. 01:40:00 2519" )
148156 self .assertEqual (
149157 thai_strftime (date , "%c" , True ), "พ ๖ ต.ค. ๐๑:๔๐:๐๐ ๒๕๑๙"
@@ -155,7 +163,7 @@ def test_thai_strftime(self):
155163 "วันพุธที่ 06 ตุลาคม พ.ศ. 2519 เวลา 01:40น. (พ 06-ต.ค.-19) % %" ,
156164 )
157165 self .assertIsNotNone (
158- thai_strftime (date , "%A%a%B%b%C%c%D%F%G%g%v%X%x%Y%y%+" )
166+ thai_strftime (date , "%A%a%B%b%C%c%D%F%G%g%v%X%x%Y%y%+%% " )
159167 )
160168
161169 # ### pythainlp.util.thai_time
@@ -169,6 +177,10 @@ def test_thai_time(self):
169177 self .assertEqual (
170178 thai_time (datetime .time (12 , 3 , 0 )), "สิบสองนาฬิกาสามนาที"
171179 )
180+ self .assertEqual (
181+ thai_time (datetime .time (12 , 3 , 1 )),
182+ "สิบสองนาฬิกาสามนาทีหนึ่งวินาที" ,
183+ )
172184 self .assertEqual (
173185 thai_time (
174186 datetime .datetime (2014 , 5 , 22 , 12 , 3 , 0 ), precision = "second"
@@ -208,6 +220,7 @@ def test_thai_time(self):
208220 def test_delete_tone (self ):
209221 self .assertEqual (delete_tone ("จิ้น" ), "จิน" )
210222 self .assertEqual (delete_tone ("เก๋า" ), "เกา" )
223+ self .assertEqual (delete_tone ("จิ้น" ), deletetone ("จิ้น" ))
211224
212225 def test_normalize (self ):
213226 self .assertEqual (normalize ("เเปลก" ), "แปลก" )
@@ -235,6 +248,7 @@ def test_isthai(self):
235248 self .assertEqual (isthai ("(ต.ค.)" , ignore_chars = ".()" ), True )
236249
237250 def test_is_native_thai (self ):
251+ self .assertEqual (is_native_thai ("เลข" ), thaicheck ("เลข" ))
238252 self .assertEqual (is_native_thai (None ), False )
239253 self .assertEqual (is_native_thai ("" ), False )
240254 self .assertEqual (is_native_thai ("116" ), False )
0 commit comments