Skip to content

Commit 22490e3

Browse files
Copilotyouknowone
andcommitted
test: move __class__ layout check to builtin_type snippet
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
1 parent b494df2 commit 22490e3

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

crates/vm/src/vm/interpreter.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,4 @@ mod tests {
169169
assert_eq!(value.as_str(), "Hello Hello Hello Hello ")
170170
})
171171
}
172-
173-
#[test]
174-
fn class_assignment_layout_mismatch_error() {
175-
Interpreter::without_stdlib(Default::default()).enter(|vm| {
176-
let scope = vm.new_scope_with_builtins();
177-
let source = r#"
178-
class TypeA:
179-
def __init__(self):
180-
self.a = 1
181-
182-
class TypeB:
183-
__slots__ = "b"
184-
def __init__(self):
185-
self.b = 2
186-
187-
obj = TypeA()
188-
try:
189-
obj.__class__ = TypeB
190-
except TypeError as e:
191-
assert str(e) == "__class__ assignment: 'TypeB' object layout differs from 'TypeA'"
192-
else:
193-
raise AssertionError("TypeError not raised")
194-
"#;
195-
vm.run_code_string(scope, source, "<test>".to_owned())
196-
.expect("script should complete without uncaught exceptions");
197-
})
198-
}
199172
}

extra_tests/snippets/builtin_type.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,26 @@ class C(B, BB):
240240
assert C.mro() == [C, B, A, BB, AA, object]
241241

242242

243+
class TypeA:
244+
def __init__(self):
245+
self.a = 1
246+
247+
248+
class TypeB:
249+
__slots__ = "b"
250+
251+
def __init__(self):
252+
self.b = 2
253+
254+
255+
obj = TypeA()
256+
with assert_raises(TypeError) as cm:
257+
obj.__class__ = TypeB
258+
assert "__class__ assignment: 'TypeB' object layout differs from 'TypeA'" in str(
259+
cm.exception
260+
)
261+
262+
243263
assert type(Exception.args).__name__ == "getset_descriptor"
244264
assert type(None).__bool__(None) is False
245265

0 commit comments

Comments
 (0)