Skip to content

Commit e652ae8

Browse files
committed
Support unicode array type.
1 parent 1e7af98 commit e652ae8

11 files changed

Lines changed: 216 additions & 158 deletions

File tree

Lib/test/test_array.py

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import array
1616
# from array import _array_reconstructor as array_reconstructor # XXX: RUSTPYTHON
1717

18-
# sizeof_wchar = array.array('u').itemsize # XXX: RUSTPYTHON
18+
sizeof_wchar = array.array('u').itemsize
1919

2020

2121
class ArraySubclass(array.array):
@@ -25,10 +25,7 @@ class ArraySubclassWithKwargs(array.array):
2525
def __init__(self, typecode, newarg=None):
2626
array.array.__init__(self)
2727

28-
# TODO: RUSTPYTHON
29-
# We did not support typecode u for unicode yet
30-
# typecodes = 'ubBhHiIlLfdqQ'
31-
typecodes = 'bBhHiIlLfdqQ'
28+
typecodes = 'ubBhHiIlLfdqQ'
3229

3330
class MiscTest(unittest.TestCase):
3431

@@ -1091,8 +1088,6 @@ def test_sizeof_without_buffer(self):
10911088
basesize = support.calcvobjsize('Pn2Pi')
10921089
support.check_sizeof(self, a, basesize)
10931090

1094-
# TODO: RUSTPYTHON
1095-
@unittest.expectedFailure
10961091
def test_initialize_with_unicode(self):
10971092
if self.typecode != 'u':
10981093
with self.assertRaises(TypeError) as cm:
@@ -1121,8 +1116,6 @@ def test_free_after_iterating(self):
11211116

11221117
class StringTest(BaseTest):
11231118

1124-
# TODO: RUSTPYTHON
1125-
@unittest.expectedFailure
11261119
def test_setitem(self):
11271120
super().test_setitem()
11281121
a = array.array(self.typecode, self.example)
@@ -1136,173 +1129,105 @@ class UnicodeTest(StringTest, unittest.TestCase):
11361129
outside = str('\x33')
11371130
minitemsize = 2
11381131

1139-
# TODO: RUSTPYTHON
1140-
@unittest.expectedFailure
11411132
def test_add(self):
11421133
super().test_add()
11431134

1144-
# TODO: RUSTPYTHON
1145-
@unittest.expectedFailure
11461135
def test_buffer(self):
11471136
super().test_buffer()
11481137

1149-
# TODO: RUSTPYTHON
1150-
@unittest.expectedFailure
11511138
def test_buffer_info(self):
11521139
super().test_buffer_info()
11531140

1154-
# TODO: RUSTPYTHON
1155-
@unittest.expectedFailure
11561141
def test_byteswap(self):
11571142
super().test_byteswap()
11581143

1159-
# TODO: RUSTPYTHON
1160-
@unittest.expectedFailure
11611144
def test_cmp(self):
11621145
super().test_cmp()
11631146

1164-
# TODO: RUSTPYTHON
1165-
@unittest.expectedFailure
11661147
def test_constructor(self):
11671148
super().test_constructor()
11681149

1169-
# TODO: RUSTPYTHON
1170-
@unittest.expectedFailure
11711150
def test_constructor_with_iterable_argument(self):
11721151
super().test_constructor_with_iterable_argument()
11731152

1174-
# TODO: RUSTPYTHON
1175-
@unittest.expectedFailure
11761153
def test_copy(self):
11771154
super().test_copy()
11781155

1179-
# TODO: RUSTPYTHON
1180-
@unittest.expectedFailure
11811156
def test_count(self):
11821157
super().test_count()
11831158

1184-
# TODO: RUSTPYTHON
1185-
@unittest.expectedFailure
11861159
def test_coveritertraverse(self):
11871160
super().test_coveritertraverse()
11881161

1189-
# TODO: RUSTPYTHON
1190-
@unittest.expectedFailure
11911162
def test_deepcopy(self):
11921163
super().test_deepcopy()
11931164

1194-
# TODO: RUSTPYTHON
1195-
@unittest.expectedFailure
11961165
def test_delitem(self):
11971166
super().test_delitem()
11981167

1199-
# TODO: RUSTPYTHON
1200-
@unittest.expectedFailure
12011168
def test_exhausted_iterator(self):
12021169
super().test_exhausted_iterator()
12031170

1204-
# TODO: RUSTPYTHON
1205-
@unittest.expectedFailure
12061171
def test_extend(self):
12071172
super().test_extend()
12081173

1209-
# TODO: RUSTPYTHON
1210-
@unittest.expectedFailure
12111174
def test_extended_getslice(self):
12121175
super().test_extended_getslice()
12131176

1214-
# TODO: RUSTPYTHON
1215-
@unittest.expectedFailure
12161177
def test_extended_set_del_slice(self):
12171178
super().test_extended_set_del_slice()
12181179

1219-
# TODO: RUSTPYTHON
1220-
@unittest.expectedFailure
12211180
def test_fromarray(self):
12221181
super().test_fromarray()
12231182

1224-
# TODO: RUSTPYTHON
1225-
@unittest.expectedFailure
12261183
def test_getitem(self):
12271184
super().test_getitem()
12281185

1229-
# TODO: RUSTPYTHON
1230-
@unittest.expectedFailure
12311186
def test_getslice(self):
12321187
super().test_getslice()
12331188

1234-
# TODO: RUSTPYTHON
1235-
@unittest.expectedFailure
12361189
def test_iadd(self):
12371190
super().test_iadd()
12381191

1239-
# TODO: RUSTPYTHON
1240-
@unittest.expectedFailure
12411192
def test_imul(self):
12421193
super().test_imul()
12431194

1244-
# TODO: RUSTPYTHON
1245-
@unittest.expectedFailure
12461195
def test_index(self):
12471196
super().test_index()
12481197

1249-
# TODO: RUSTPYTHON
1250-
@unittest.expectedFailure
12511198
def test_insert(self):
12521199
super().test_insert()
12531200

1254-
# TODO: RUSTPYTHON
1255-
@unittest.expectedFailure
12561201
def test_len(self):
12571202
super().test_len()
12581203

1259-
# TODO: RUSTPYTHON
1260-
@unittest.expectedFailure
12611204
def test_mul(self):
12621205
super().test_mul()
12631206

1264-
# TODO: RUSTPYTHON
1265-
@unittest.expectedFailure
12661207
def test_pop(self):
12671208
super().test_pop()
12681209

1269-
# TODO: RUSTPYTHON
1270-
@unittest.expectedFailure
12711210
def test_remove(self):
12721211
super().test_remove()
12731212

1274-
# TODO: RUSTPYTHON
1275-
@unittest.expectedFailure
12761213
def test_repr(self):
12771214
super().test_repr()
12781215

1279-
# TODO: RUSTPYTHON
1280-
@unittest.expectedFailure
12811216
def test_reverse(self):
12821217
super().test_reverse()
12831218

1284-
# TODO: RUSTPYTHON
1285-
@unittest.expectedFailure
12861219
def test_setslice(self):
12871220
super().test_setslice()
12881221

1289-
# TODO: RUSTPYTHON
1290-
@unittest.expectedFailure
12911222
def test_str(self):
12921223
super().test_str()
12931224

1294-
# TODO: RUSTPYTHON
1295-
@unittest.expectedFailure
12961225
def test_tofrombytes(self):
12971226
super().test_tofrombytes()
12981227

1299-
# TODO: RUSTPYTHON
1300-
@unittest.expectedFailure
13011228
def test_tofromlist(self):
13021229
super().test_tofromlist()
13031230

1304-
# TODO: RUSTPYTHON
1305-
@unittest.expectedFailure
13061231
def test_unicode(self):
13071232
self.assertRaises(TypeError, array.array, 'b', 'foo')
13081233

@@ -1323,8 +1248,6 @@ def test_unicode(self):
13231248

13241249
self.assertRaises(TypeError, a.fromunicode)
13251250

1326-
# TODO: RUSTPYTHON
1327-
@unittest.expectedFailure
13281251
def test_issue17223(self):
13291252
# this used to crash
13301253
if sizeof_wchar == 4:

Lib/test/test_io.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,8 +2596,6 @@ def setUp(self):
25962596
def tearDown(self):
25972597
support.unlink(support.TESTFN)
25982598

2599-
# TODO: RUSTPYTHON
2600-
@unittest.expectedFailure
26012599
def test_constructor(self):
26022600
r = self.BytesIO(b"\xc3\xa9\n\n")
26032601
b = self.BufferedReader(r, 1000)
@@ -2935,8 +2933,6 @@ def test_error_through_destructor(self):
29352933

29362934
# Systematic tests of the text I/O API
29372935

2938-
# TODO: RUSTPYTHON
2939-
@unittest.expectedFailure
29402936
def test_basic_io(self):
29412937
for chunksize in (1, 2, 3, 4, 5, 15, 16, 17, 31, 32, 33, 63, 64, 65):
29422938
for enc in "ascii", "latin-1", "utf-8" :# , "utf-16-be", "utf-16-le":
@@ -2988,8 +2984,6 @@ def multi_line_test(self, f, enc):
29882984
rlines.append((pos, line))
29892985
self.assertEqual(rlines, wlines)
29902986

2991-
# TODO: RUSTPYTHON
2992-
@unittest.expectedFailure
29932987
def test_telling(self):
29942988
f = self.open(support.TESTFN, "w+", encoding="utf-8")
29952989
p0 = f.tell()
@@ -3608,8 +3602,6 @@ def seekable(self): return True
36083602
F.tell = lambda x: 0
36093603
t = self.TextIOWrapper(F(), encoding='utf-8')
36103604

3611-
# TODO: RUSTPYTHON
3612-
@unittest.expectedFailure
36133605
def test_reconfigure_encoding_read(self):
36143606
# latin1 -> utf8
36153607
# (latin1 can decode utf-8 encoded string)
@@ -3762,6 +3754,26 @@ class CTextIOWrapperTest(TextIOWrapperTest):
37623754
io = io
37633755
shutdown_error = "RuntimeError: could not find io module state"
37643756

3757+
# TODO: RUSTPYTHON
3758+
@unittest.expectedFailure
3759+
def test_constructor(self):
3760+
super().test_constructor()
3761+
3762+
# TODO: RUSTPYTHON
3763+
@unittest.expectedFailure
3764+
def test_reconfigure_encoding_read(self):
3765+
super().test_reconfigure_encoding_read()
3766+
3767+
# TODO: RUSTPYTHON
3768+
@unittest.expectedFailure
3769+
def test_basic_io(self):
3770+
super().test_basic_io()
3771+
3772+
# TODO: RUSTPYTHON
3773+
@unittest.expectedFailure
3774+
def test_telling(self):
3775+
super().test_telling()
3776+
37653777
# TODO: RUSTPYTHON
37663778
@unittest.expectedFailure
37673779
def test_uninitialized(self):
@@ -3917,8 +3929,6 @@ def test_newlines(self):
39173929
def test_line_buffering(self):
39183930
super().test_line_buffering()
39193931

3920-
# TODO: RUSTPYTHON
3921-
@unittest.expectedFailure
39223932
def test_seeking_too(self):
39233933
super().test_seeking_too()
39243934

@@ -3927,8 +3937,6 @@ def test_seeking_too(self):
39273937
def test_bufio_write_through(self):
39283938
super().test_bufio_write_through()
39293939

3930-
# TODO: RUSTPYTHON
3931-
@unittest.expectedFailure
39323940
def test_seeking(self):
39333941
super().test_seeking()
39343942

Lib/test/test_ntpath.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ def test_splitext(self):
9595
tester('ntpath.splitext("xx\\foo.bar.ext")', ('xx\\foo.bar', '.ext'))
9696
tester('ntpath.splitext("c:a/b\\c.d")', ('c:a/b\\c', '.d'))
9797

98-
# TODO: RUSTPYTHON
99-
@unittest.expectedFailure
10098
def test_splitdrive(self):
10199
tester('ntpath.splitdrive("c:\\foo\\bar")',
102100
('c:', '\\foo\\bar'))
@@ -479,8 +477,6 @@ def test_expandvars(self):
479477
tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")
480478
tester('ntpath.expandvars("bar\'%foo%")', "bar\'%foo%")
481479

482-
# TODO: RUSTPYTHON
483-
@unittest.expectedFailure
484480
@unittest.skipUnless(support.FS_NONASCII, 'need support.FS_NONASCII')
485481
def test_expandvars_nonascii(self):
486482
def check(value, expected):
@@ -730,8 +726,6 @@ class NtCommonTest(test_genericpath.CommonTest, unittest.TestCase):
730726
pathmodule = ntpath
731727
attributes = ['relpath']
732728

733-
# TODO: RUSTPYTHON
734-
@unittest.expectedFailure
735729
def test_expandvars_nonascii(self):
736730
super().test_expandvars_nonascii()
737731

Lib/test/test_re.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,6 @@ def test_bug_6561(self):
13981398
for x in not_decimal_digits:
13991399
self.assertIsNone(re.match(r'^\d$', x))
14001400

1401-
# TODO: RUSTPYTHON
1402-
@unittest.expectedFailure
14031401
def test_empty_array(self):
14041402
# SF buf 1647541
14051403
import array

Lib/test/test_strtod.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def test_short_halfway_cases(self):
146146
digits *= 5
147147
exponent -= 1
148148

149+
# TODO: RUSTPYTHON fails on debug mode
149150
def test_halfway_cases(self):
150151
# test halfway cases for the round-half-to-even rule
151152
for i in range(100 * TEST_SIZE):

Lib/test/test_traceback.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ def syntax_error_with_caret_non_ascii(self):
4646
def syntax_error_bad_indentation2(self):
4747
compile(" print(2)", "?", "exec")
4848

49-
# TODO: RUSTPYTHON
50-
@unittest.expectedFailure
5149
def test_caret(self):
5250
err = self.get_exception_format(self.syntax_error_with_caret,
5351
SyntaxError)

Lib/test/test_unicode.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ def test_count(self):
199199
self.checkequal(0, 'a' * 10, 'count', 'a\U00100304')
200200
self.checkequal(0, '\u0102' * 10, 'count', '\u0102\U00100304')
201201

202-
# TODO: RUSTPYTHON
203-
@unittest.expectedFailure
204202
def test_find(self):
205203
string_tests.CommonTest.test_find(self)
206204
# test implementation details of the memchr fast path
@@ -260,8 +258,6 @@ def test_rfind(self):
260258
self.checkequal(-1, 'a' * 100, 'rfind', '\U00100304a')
261259
self.checkequal(-1, '\u0102' * 100, 'rfind', '\U00100304\u0102')
262260

263-
# TODO: RUSTPYTHON
264-
@unittest.expectedFailure
265261
def test_index(self):
266262
string_tests.CommonTest.test_index(self)
267263
self.checkequalnofix(0, 'abcdefghiabc', 'index', '')

vm/src/builtins/memory.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ type PyMemoryViewRef = PyRef<PyMemoryView>;
5454
#[pyimpl(with(Hashable, Comparable, AsBuffer))]
5555
impl PyMemoryView {
5656
fn parse_format(format: &str, vm: &VirtualMachine) -> PyResult<FormatSpec> {
57-
FormatSpec::parse(format)
58-
.map_err(|msg| vm.new_exception_msg(vm.ctx.types.memoryview_type.clone(), msg))
57+
FormatSpec::parse(format, vm)
5958
}
6059

6160
pub fn from_buffer(

0 commit comments

Comments
 (0)