1
- # Copyright (c) 2018, 2021 , Oracle and/or its affiliates. All rights reserved.
1
+ # Copyright (c) 2018, 2025 , Oracle and/or its affiliates. All rights reserved.
2
2
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3
3
#
4
4
# The Universal Permissive License (UPL), Version 1.0
37
37
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
38
# SOFTWARE.
39
39
40
+ import unicodedata
41
+ import unittest
40
42
41
- def assert_raises (err , fn , * args , ** kwargs ):
42
- raised = False
43
- try :
44
- fn (* args , ** kwargs )
45
- except err :
46
- raised = True
47
- assert raised
43
+ class TestUnicodedata (unittest .TestCase ):
48
44
45
+ def test_args_validation (self ):
46
+ self .assertRaises (TypeError , unicodedata .category , None )
47
+ self .assertRaises (TypeError , unicodedata .bidirectional , None )
48
+ self .assertRaises (TypeError , unicodedata .name , None )
49
49
50
- def test_args_validation ():
51
- import unicodedata
52
- assert_raises (TypeError , unicodedata .category , None )
53
- assert_raises (TypeError , unicodedata .bidirectional , None )
54
- assert_raises (TypeError , unicodedata .name , None )
55
50
51
+ def test_normalize (self ):
52
+ self .assertRaises (TypeError , unicodedata .normalize )
53
+ self .assertRaises (ValueError , unicodedata .normalize , 'unknown' , 'xx' )
54
+ assert unicodedata .normalize ('NFKC' , '' ) == ''
56
55
57
- def test_normalize ():
58
- import unicodedata
59
- assert_raises (TypeError , unicodedata .normalize )
60
- assert_raises (ValueError , unicodedata .normalize , 'unknown' , 'xx' )
61
- assert unicodedata .normalize ('NFKC' , '' ) == ''
62
56
57
+ def test_category (self ):
58
+ assert unicodedata .category ('\uFFFE ' ) == 'Cn'
59
+ assert unicodedata .category ('a' ) == 'Ll'
60
+ assert unicodedata .category ('A' ) == 'Lu'
61
+ self .assertRaises (TypeError , unicodedata .category )
62
+ self .assertRaises (TypeError , unicodedata .category , 'xx' )
63
63
64
- def test_category ():
65
- import unicodedata
66
- assert unicodedata .category ('\uFFFE ' ) == 'Cn'
67
- assert unicodedata .category ('a' ) == 'Ll'
68
- assert unicodedata .category ('A' ) == 'Lu'
69
- assert_raises (TypeError , unicodedata .category )
70
- assert_raises (TypeError , unicodedata .category , 'xx' )
64
+
65
+ def test_lookup (self ):
66
+ unicode_name = "ARABIC SMALL HIGH LIGATURE ALEF WITH LAM WITH YEH"
67
+ self .assertEqual (unicodedata .lookup (unicode_name ), "\u0616 " )
68
+
69
+ unicode_name_alias = "ARABIC SMALL HIGH LIGATURE ALEF WITH YEH BARREE"
70
+ self .assertEqual (unicodedata .lookup (unicode_name_alias ), "\u0616 " )
71
+
72
+ with self .assertRaisesRegex (KeyError , "undefined character name 'wrong-name'" ):
73
+ unicodedata .lookup ("wrong-name" )
74
+
75
+ with self .assertRaisesRegex (KeyError , "name too long" ):
76
+ unicodedata .lookup ("a" * 257 )
77
+
78
+
79
+ def test_east_asian_width (self ):
80
+ list = [1 , 2 , 3 ]
81
+ with self .assertRaisesRegex (TypeError , r"east_asian_width\(\) argument must be a unicode character, not list" ):
82
+ unicodedata .east_asian_width (list )
83
+
84
+ multi_character_string = "abc"
85
+ with self .assertRaisesRegex (TypeError , r"east_asian_width\(\) argument must be a unicode character, not str" ):
86
+ unicodedata .east_asian_width (multi_character_string )
87
+
88
+ empty_string = ""
89
+ with self .assertRaisesRegex (TypeError , r"east_asian_width\(\) argument must be a unicode character, not str" ):
90
+ unicodedata .east_asian_width (empty_string )
91
+
92
+
93
+ def test_combining (self ):
94
+ list = [1 , 2 , 3 ]
95
+ with self .assertRaisesRegex (TypeError , r"combining\(\) argument must be a unicode character, not list" ):
96
+ unicodedata .combining (list )
97
+
98
+ multi_character_string = "abc"
99
+ with self .assertRaisesRegex (TypeError , r"combining\(\) argument must be a unicode character, not str" ):
100
+ unicodedata .combining (multi_character_string )
101
+
102
+ empty_string = ""
103
+ with self .assertRaisesRegex (TypeError , r"combining\(\) argument must be a unicode character, not str" ):
104
+ unicodedata .combining (empty_string )
0 commit comments