|
1 | 1 | """ Test script for the unicodedata module.
|
2 | 2 |
|
3 |
| -Written by Marc-Andre Lemburg ([email protected]). |
| 3 | + Written by Marc-Andre Lemburg ([email protected]). |
4 | 4 |
|
5 |
| -(c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
| 5 | + (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
6 | 6 |
|
7 | 7 | """#"
|
8 |
| -from test_support import verbose |
9 |
| -import sys |
| 8 | +import sha |
10 | 9 |
|
11 |
| -# Test Unicode database APIs |
| 10 | +def test_methods(): |
| 11 | + |
| 12 | + h = sha.sha() |
| 13 | + for i in range(65536): |
| 14 | + char = unichr(i) |
| 15 | + data = [ |
| 16 | + |
| 17 | + # Predicates (single char) |
| 18 | + char.isalnum() and u'1' or u'0', |
| 19 | + char.isalpha() and u'1' or u'0', |
| 20 | + char.isdecimal() and u'1' or u'0', |
| 21 | + char.isdigit() and u'1' or u'0', |
| 22 | + char.islower() and u'1' or u'0', |
| 23 | + char.isnumeric() and u'1' or u'0', |
| 24 | + char.isspace() and u'1' or u'0', |
| 25 | + char.istitle() and u'1' or u'0', |
| 26 | + char.isupper() and u'1' or u'0', |
| 27 | + |
| 28 | + # Predicates (multiple chars) |
| 29 | + (char + u'abc').isalnum() and u'1' or u'0', |
| 30 | + (char + u'abc').isalpha() and u'1' or u'0', |
| 31 | + (char + u'123').isdecimal() and u'1' or u'0', |
| 32 | + (char + u'123').isdigit() and u'1' or u'0', |
| 33 | + (char + u'abc').islower() and u'1' or u'0', |
| 34 | + (char + u'123').isnumeric() and u'1' or u'0', |
| 35 | + (char + u' \t').isspace() and u'1' or u'0', |
| 36 | + (char + u'abc').istitle() and u'1' or u'0', |
| 37 | + (char + u'ABC').isupper() and u'1' or u'0', |
| 38 | + |
| 39 | + # Mappings (single char) |
| 40 | + char.lower(), |
| 41 | + char.upper(), |
| 42 | + char.title(), |
| 43 | + |
| 44 | + # Mappings (multiple chars) |
| 45 | + (char + u'abc').lower(), |
| 46 | + (char + u'ABC').upper(), |
| 47 | + (char + u'abc').title(), |
| 48 | + (char + u'ABC').title(), |
| 49 | + |
| 50 | + ] |
| 51 | + h.update(u''.join(data).encode('unicode-internal')) |
| 52 | + return h.hexdigest() |
| 53 | + |
| 54 | +def test_unicodedata(): |
| 55 | + |
| 56 | + h = sha.sha() |
| 57 | + for i in range(65536): |
| 58 | + char = unichr(i) |
| 59 | + data = [ |
| 60 | + # Properties |
| 61 | + str(unicodedata.digit(char, -1)), |
| 62 | + str(unicodedata.numeric(char, -1)), |
| 63 | + str(unicodedata.decimal(char, -1)), |
| 64 | + unicodedata.category(char), |
| 65 | + unicodedata.bidirectional(char), |
| 66 | + unicodedata.decomposition(char), |
| 67 | + str(unicodedata.mirrored(char)), |
| 68 | + str(unicodedata.combining(char)), |
| 69 | + ] |
| 70 | + h.update(''.join(data)) |
| 71 | + return h.hexdigest() |
| 72 | + |
| 73 | +### Run tests |
| 74 | + |
| 75 | +print 'Testing Unicode Database...' |
| 76 | +print 'Methods:', |
| 77 | +print test_methods() |
| 78 | + |
| 79 | +# In case unicodedata is not available, this will raise an ImportError, |
| 80 | +# but still test the above cases... |
12 | 81 | import unicodedata
|
| 82 | +print 'Functions:', |
| 83 | +print test_unicodedata() |
13 | 84 |
|
14 |
| -print 'Testing unicodedata module...', |
| 85 | +# Some additional checks of the API: |
| 86 | +print 'API:', |
15 | 87 |
|
16 | 88 | assert unicodedata.digit(u'A',None) is None
|
17 | 89 | assert unicodedata.digit(u'9') == 9
|
|
47 | 119 | assert unicodedata.combining(u'a') == 0
|
48 | 120 | assert unicodedata.combining(u'\u20e1') == 230
|
49 | 121 |
|
50 |
| -print 'done.' |
| 122 | +print 'ok' |
0 commit comments