Add testcase for logging module.

This commit is contained in:
Windel Bouwman committed 2019-07-10 21:02:04 +02:00
1 parent 55fbe7f269
commit 140ad71f05
2 files changed
+31 -1

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import io
import sys
f = io.StringIO()
sys.stderr = f
import logging
logging.error('WOOT')
logging.warning('WARN')
print(f.getvalue())
+17 -1
View File
@@ -5,7 +5,7 @@
use super::objcode::PyCodeRef;
use super::objdict::PyDictRef;
use crate::frame::FrameRef;
use crate::pyobject::{PyContext, PyResult};
use crate::pyobject::{PyContext, PyObjectRef, PyResult};
use crate::vm::VirtualMachine;
pub fn init(context: &PyContext) {
@@ -13,7 +13,10 @@ pub fn init(context: &PyContext) {
"__new__" => context.new_rustfunc(FrameRef::new),
"__repr__" => context.new_rustfunc(FrameRef::repr),
"f_locals" => context.new_property(FrameRef::flocals),
"f_globals" => context.new_property(FrameRef::f_globals),
"f_code" => context.new_property(FrameRef::fcode),
"f_back" => context.new_property(FrameRef::f_back),
"f_lasti" => context.new_property(FrameRef::f_lasti),
});
}
@@ -27,6 +30,10 @@ impl FrameRef {
"<frame object at .. >".to_string()
}
fn f_globals(self, _vm: &VirtualMachine) -> PyDictRef {
self.scope.globals.clone()
}
fn flocals(self, _vm: &VirtualMachine) -> PyDictRef {
self.scope.get_locals()
}
@@ -34,4 +41,13 @@ impl FrameRef {
fn fcode(self, vm: &VirtualMachine) -> PyCodeRef {
vm.ctx.new_code_object(self.code.clone())
}
fn f_back(self, vm: &VirtualMachine) -> PyObjectRef {
// TODO: how to retrieve the upper stack frame??
vm.ctx.none()
}
fn f_lasti(self, vm: &VirtualMachine) -> PyObjectRef {
vm.ctx.new_int(*self.lasti.borrow())
}
}