Skip to content

Commit 3e5b196

Browse files
committed
mark fail tests
1 parent 861e821 commit 3e5b196

8 files changed

Lines changed: 40 additions & 28 deletions

File tree

Lib/test/test_bytes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,8 @@ def test_sq_item(self):
989989
class BytesTest(BaseBytesTest, unittest.TestCase):
990990
type2test = bytes
991991

992+
# TODO: RUSTPYTHON
993+
@unittest.expectedFailure
992994
def test_getitem_error(self):
993995
b = b'python'
994996
msg = "byte indices must be integers or slices"
@@ -1181,12 +1183,16 @@ class BufferBlocked(bytearray):
11811183
class ByteArrayTest(BaseBytesTest, unittest.TestCase):
11821184
type2test = bytearray
11831185

1186+
# TODO: RUSTPYTHON
1187+
@unittest.expectedFailure
11841188
def test_getitem_error(self):
11851189
b = bytearray(b'python')
11861190
msg = "bytearray indices must be integers or slices"
11871191
with self.assertRaisesRegex(TypeError, msg):
11881192
b['a']
11891193

1194+
# TODO: RUSTPYTHON
1195+
@unittest.expectedFailure
11901196
def test_setitem_error(self):
11911197
b = bytearray(b'python')
11921198
msg = "bytearray indices must be integers or slices"

Lib/test/test_tuple.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
class TupleTest(seq_tests.CommonTest):
1919
type2test = tuple
2020

21+
# TODO: RUSTPYTHON
22+
@unittest.expectedFailure
2123
def test_getitem_error(self):
2224
t = ()
2325
msg = "tuple indices must be integers or slices"

Lib/test/test_xml_etree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,7 @@ def __index__(self):
25152515
e.append(ET.Element('child'))
25162516
e[0:10:X()] # shouldn't crash
25172517

2518+
@unittest.skip("TODO: RUSTPYTHON, hangs")
25182519
def test_ass_subscr(self):
25192520
# Issue #27863
25202521
class X:

vm/src/builtins/iter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ impl PyValue for PySequenceIterator {
176176
#[pyimpl(with(IterNext))]
177177
impl PySequenceIterator {
178178
pub fn new(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<Self> {
179-
let seq = PySequence::from(obj.as_ref());
180-
seq.try_protocol(vm)?;
179+
let seq = PySequence::try_protocol(obj.as_ref(), vm)?;
181180
let seq_methods = seq.methods_cow(vm).clone();
182181
Ok(Self {
183182
seq_methods,

vm/src/builtins/mappingproxy.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use super::{PyDict, PyGenericAlias, PyList, PyStr, PyStrRef, PyTuple, PyTypeRef}
44
use crate::{
55
function::{IntoPyObject, OptionalArg},
66
protocol::{PyMapping, PyMappingMethods, PySequence, PySequenceMethods},
7+
pyref_type_error,
78
types::{AsMapping, AsSequence, Constructor, Iterable},
89
PyClassImpl, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
9-
TypeProtocol, VirtualMachine, pyref_type_error,
10+
TypeProtocol, VirtualMachine,
1011
};
1112

1213
#[pyclass(module = false, name = "mappingproxy")]

vm/src/builtins/memory.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use crate::{
99
lock::OnceCell,
1010
},
1111
function::{FuncArgs, IntoPyObject, OptionalArg},
12-
protocol::{BufferDescriptor, BufferMethods, PyBuffer, PyMappingMethods, VecBuffer, PySequenceMethods},
12+
protocol::{
13+
BufferDescriptor, BufferMethods, PyBuffer, PyMappingMethods, PySequenceMethods, VecBuffer,
14+
},
1315
sequence::SequenceOp,
1416
sliceable::wrap_index,
1517
stdlib::pystruct::FormatSpec,

vm/src/builtins/pystr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::{
1515
Iterable, PyComparisonOp, Unconstructible,
1616
},
1717
utils::Either,
18-
IdProtocol, PyClassImpl, PyComparisonValue, PyContext, PyObject, PyObjectRef,
19-
PyObjectView, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
18+
IdProtocol, PyClassImpl, PyComparisonValue, PyContext, PyObject, PyObjectRef, PyObjectView,
19+
PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
2020
};
2121
use ascii::{AsciiStr, AsciiString};
2222
use bstr::ByteSlice;

vm/src/protocol/sequence.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ impl<'a> PySequence<'a> {
7272
methods: OnceCell::from(methods),
7373
}
7474
}
75+
76+
pub fn try_protocol(obj: &'a PyObject, vm: &VirtualMachine) -> PyResult<Self> {
77+
let zelf = Self::from(obj);
78+
if zelf.check(vm) {
79+
Ok(zelf)
80+
} else {
81+
Err(vm.new_type_error(format!("'{}' is not a sequence", obj.class())))
82+
}
83+
}
7584
}
7685

7786
impl PySequence<'_> {
@@ -80,18 +89,10 @@ impl PySequence<'_> {
8089
}
8190

8291
// PySequence_Check
83-
pub fn has_protocol(&self, vm: &VirtualMachine) -> bool {
92+
pub fn check(&self, vm: &VirtualMachine) -> bool {
8493
self.methods(vm).item.is_some()
8594
}
8695

87-
pub fn try_protocol(&self, vm: &VirtualMachine) -> PyResult<()> {
88-
if self.has_protocol(vm) {
89-
Ok(())
90-
} else {
91-
Err(vm.new_type_error(format!("'{}' is not a sequence", self.obj.class().name())))
92-
}
93-
}
94-
9596
pub fn methods(&self, vm: &VirtualMachine) -> &PySequenceMethods {
9697
self.methods_cow(vm).borrow()
9798
}
@@ -116,7 +117,7 @@ impl PySequence<'_> {
116117
self.length_opt(vm).ok_or_else(|| {
117118
vm.new_type_error(format!(
118119
"'{}' is not a sequence or has no len()",
119-
self.obj.class().name()
120+
self.obj.class()
120121
))
121122
})?
122123
}
@@ -127,15 +128,15 @@ impl PySequence<'_> {
127128
}
128129

129130
// if both arguments apear to be sequences, try fallback to __add__
130-
if self.has_protocol(vm) && PySequence::from(other).has_protocol(vm) {
131+
if self.check(vm) && PySequence::from(other).check(vm) {
131132
let ret = vm._add(self.obj, other)?;
132133
if let PyArithmeticValue::Implemented(ret) = PyArithmeticValue::from_object(vm, ret) {
133134
return Ok(ret);
134135
}
135136
}
136137
Err(vm.new_type_error(format!(
137138
"'{}' object can't be concatenated",
138-
self.obj.class().name()
139+
self.obj.class()
139140
)))
140141
}
141142

@@ -145,15 +146,15 @@ impl PySequence<'_> {
145146
}
146147

147148
// try fallback to __mul__
148-
if self.has_protocol(vm) {
149+
if self.check(vm) {
149150
let ret = vm._mul(self.obj, &n.into_pyobject(vm))?;
150151
if let PyArithmeticValue::Implemented(ret) = PyArithmeticValue::from_object(vm, ret) {
151152
return Ok(ret);
152153
}
153154
}
154155
Err(vm.new_type_error(format!(
155156
"'{}' object can't be repeated",
156-
self.obj.class().name()
157+
self.obj.class()
157158
)))
158159
}
159160

@@ -166,15 +167,15 @@ impl PySequence<'_> {
166167
}
167168

168169
// if both arguments apear to be sequences, try fallback to __iadd__
169-
if self.has_protocol(vm) && PySequence::from(other).has_protocol(vm) {
170+
if self.check(vm) && PySequence::from(other).check(vm) {
170171
let ret = vm._iadd(self.obj, other)?;
171172
if let PyArithmeticValue::Implemented(ret) = PyArithmeticValue::from_object(vm, ret) {
172173
return Ok(ret);
173174
}
174175
}
175176
Err(vm.new_type_error(format!(
176177
"'{}' object can't be concatenated",
177-
self.obj.class().name()
178+
self.obj.class()
178179
)))
179180
}
180181

@@ -186,15 +187,15 @@ impl PySequence<'_> {
186187
return f(self, n, vm);
187188
}
188189

189-
if self.has_protocol(vm) {
190+
if self.check(vm) {
190191
let ret = vm._imul(self.obj, &n.into_pyobject(vm))?;
191192
if let PyArithmeticValue::Implemented(ret) = PyArithmeticValue::from_object(vm, ret) {
192193
return Ok(ret);
193194
}
194195
}
195196
Err(vm.new_type_error(format!(
196197
"'{}' object can't be repeated",
197-
self.obj.class().name()
198+
self.obj.class()
198199
)))
199200
}
200201

@@ -204,7 +205,7 @@ impl PySequence<'_> {
204205
}
205206
Err(vm.new_type_error(format!(
206207
"'{}' is not a sequence or does not support indexing",
207-
self.obj.class().name()
208+
self.obj.class()
208209
)))
209210
}
210211

@@ -214,7 +215,7 @@ impl PySequence<'_> {
214215
}
215216
Err(vm.new_type_error(format!(
216217
"'{}' is not a sequence or doesn't support item {}",
217-
self.obj.class().name(),
218+
self.obj.class(),
218219
if value.is_some() {
219220
"assignment"
220221
} else {
@@ -242,7 +243,7 @@ impl PySequence<'_> {
242243
} else {
243244
Err(vm.new_type_error(format!(
244245
"'{}' object is unsliceable",
245-
self.obj.class().name()
246+
self.obj.class()
246247
)))
247248
}
248249
}
@@ -265,7 +266,7 @@ impl PySequence<'_> {
265266
} else {
266267
Err(vm.new_type_error(format!(
267268
"'{}' object doesn't support slice {}",
268-
self.obj.class().name(),
269+
self.obj.class(),
269270
if value.is_some() {
270271
"assignment"
271272
} else {

0 commit comments

Comments
 (0)