##// END OF EJS Templates
Update unicode ranges to fix test on nightly....
Matthias Bussonnier -
Show More
@@ -162,7 +162,7 b' except ImportError:'
162 # write this). With below range we cover them all, with a density of ~67%
162 # write this). With below range we cover them all, with a density of ~67%
163 # biggest next gap we consider only adds up about 1% density and there are 600
163 # biggest next gap we consider only adds up about 1% density and there are 600
164 # gaps that would need hard coding.
164 # gaps that would need hard coding.
165 _UNICODE_RANGES = [(32, 0x2fa1e), (0xe0001, 0xe01f0)]
165 _UNICODE_RANGES = [(32, 0x3134b), (0xe0001, 0xe01f0)]
166
166
167 # Public API
167 # Public API
168 __all__ = ['Completer','IPCompleter']
168 __all__ = ['Completer','IPCompleter']
@@ -33,6 +33,40 b' from nose.tools import assert_in, assert_not_in'
33 # Test functions
33 # Test functions
34 # -----------------------------------------------------------------------------
34 # -----------------------------------------------------------------------------
35
35
36 def recompute_unicode_ranges():
37 """
38 utility to recompute the largest unicode range without any characters
39
40 use to recompute the gap in the global _UNICODE_RANGES of completer.py
41 """
42 import itertools
43 import unicodedata
44 valid = []
45 for c in range(0,0x10FFFF + 1):
46 try:
47 unicodedata.name(chr(c))
48 except ValueError:
49 continue
50 valid.append(c)
51
52 def ranges(i):
53 for a, b in itertools.groupby(enumerate(i), lambda pair: pair[1] - pair[0]):
54 b = list(b)
55 yield b[0][1], b[-1][1]
56
57 rg = list(ranges(valid))
58 lens = []
59 gap_lens = []
60 pstart, pstop = 0,0
61 for start, stop in rg:
62 lens.append(stop-start)
63 gap_lens.append((start - pstop, hex(pstop), hex(start), f'{round((start - pstop)/0xe01f0*100)}%'))
64 pstart, pstop = start, stop
65
66 return sorted(gap_lens)[-1]
67
68
69
36 def test_unicode_range():
70 def test_unicode_range():
37 """
71 """
38 Test that the ranges we test for unicode names give the same number of
72 Test that the ranges we test for unicode names give the same number of
@@ -47,10 +81,24 b' def test_unicode_range():'
47
81
48 # do not inline the len() or on error pytest will try to print the 130 000 +
82 # do not inline the len() or on error pytest will try to print the 130 000 +
49 # elements.
83 # elements.
50 assert len_exp == len_test
84 message = None
85 if len_exp != len_test or len_exp > 131808:
86 size, start, stop, prct = recompute_unicode_ranges()
87 message = f"""_UNICODE_RANGES likely wrong and need updating. This is
88 likely due to a new release of Python. We've find that the biggest gap
89 in unicode characters has reduces in size to be {size} charaters
90 ({prct}), from {start}, to {stop}. In completer.py likely update to
91
92 _UNICODE_RANGES = [(32, {start}), ({stop}, 0xe01f0)]
93
94 And update the assertion below to use
95
96 len_exp <= {len_exp}
97 """
98 assert len_exp == len_test, message
51
99
52 # fail if new unicode symbols have been added.
100 # fail if new unicode symbols have been added.
53 assert len_exp <= 131808
101 assert len_exp <= 137714, message
54
102
55
103
56 @contextmanager
104 @contextmanager
General Comments 0
You need to be logged in to leave comments. Login now