Sitelet https://github.com/RustPython/RustPython/pull/7916/commits/899fac4a9b8ac57557a47c0d4e246732198953e6
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add tests for Mode::BlockExpr and VirtualMachine::run_block_expr
test_block_expr_return_const() panics currently.
  • Loading branch information
im-0 committed May 18, 2026
commit 899fac4a9b8ac57557a47c0d4e246732198953e6
32 changes: 32 additions & 0 deletions crates/vm/src/vm/python_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,35 @@ mod file_run {
Ok(crate::import::check_pyc_magic_number_bytes(&buf))
}
}

#[cfg(test)]
mod tests {
use rustpython_vm::Interpreter;

fn interpreter() -> Interpreter {
Interpreter::without_stdlib(Default::default())
}

#[test]
fn test_block_expr_return_const() {
interpreter().enter(|vm| {
let scope = vm.new_scope_with_builtins();
let value = vm.unwrap_pyresult(vm.run_block_expr(scope, "1"));
let value = vm.unwrap_pyresult(value.try_int(vm));
let value: u32 = vm.unwrap_pyresult(value.try_to_primitive(vm));
assert_eq!(value, 1);
})
}

#[test]
fn test_block_expr_return_nonconst() {
interpreter().enter(|vm| {
let scope = vm.new_scope_with_builtins();
vm.unwrap_pyresult(scope.globals.set_item("x", vm.new_pyobj(3), vm));
let value = vm.unwrap_pyresult(vm.run_block_expr(scope, "2 + x"));
let value = vm.unwrap_pyresult(value.try_int(vm));
let value: u32 = vm.unwrap_pyresult(value.try_to_primitive(vm));
assert_eq!(value, 5);
})
}
}