Skip to content

Commit 140ad71

Browse files
committed
Add testcase for logging module.
1 parent 55fbe7f commit 140ad71

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

tests/snippets/test_logging.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
import io
3+
import sys
4+
5+
f = io.StringIO()
6+
sys.stderr = f
7+
8+
import logging
9+
10+
logging.error('WOOT')
11+
logging.warning('WARN')
12+
13+
print(f.getvalue())
14+

vm/src/obj/objframe.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
use super::objcode::PyCodeRef;
66
use super::objdict::PyDictRef;
77
use crate::frame::FrameRef;
8-
use crate::pyobject::{PyContext, PyResult};
8+
use crate::pyobject::{PyContext, PyObjectRef, PyResult};
99
use crate::vm::VirtualMachine;
1010

1111
pub fn init(context: &PyContext) {
1212
extend_class!(context, &context.frame_type, {
1313
"__new__" => context.new_rustfunc(FrameRef::new),
1414
"__repr__" => context.new_rustfunc(FrameRef::repr),
1515
"f_locals" => context.new_property(FrameRef::flocals),
16+
"f_globals" => context.new_property(FrameRef::f_globals),
1617
"f_code" => context.new_property(FrameRef::fcode),
18+
"f_back" => context.new_property(FrameRef::f_back),
19+
"f_lasti" => context.new_property(FrameRef::f_lasti),
1720
});
1821
}
1922

@@ -27,11 +30,24 @@ impl FrameRef {
2730
"<frame object at .. >".to_string()
2831
}
2932

33+
fn f_globals(self, _vm: &VirtualMachine) -> PyDictRef {
34+
self.scope.globals.clone()
35+
}
36+
3037
fn flocals(self, _vm: &VirtualMachine) -> PyDictRef {
3138
self.scope.get_locals()
3239
}
3340

3441
fn fcode(self, vm: &VirtualMachine) -> PyCodeRef {
3542
vm.ctx.new_code_object(self.code.clone())
3643
}
44+
45+
fn f_back(self, vm: &VirtualMachine) -> PyObjectRef {
46+
// TODO: how to retrieve the upper stack frame??
47+
vm.ctx.none()
48+
}
49+
50+
fn f_lasti(self, vm: &VirtualMachine) -> PyObjectRef {
51+
vm.ctx.new_int(*self.lasti.borrow())
52+
}
3753
}

0 commit comments

Comments
 (0)