From 140ad71f05d2de899bdc4acaf6d7068add69864c Mon Sep 17 00:00:00 2001 From: Windel Bouwman Date: Wed, 10 Jul 2019 21:02:04 +0200 Subject: [PATCH] Add testcase for logging module. --- tests/snippets/test_logging.py | 14 ++++++++++++++ vm/src/obj/objframe.rs | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/snippets/test_logging.py diff --git a/tests/snippets/test_logging.py b/tests/snippets/test_logging.py new file mode 100644 index 000000000..ee1ac2498 --- /dev/null +++ b/tests/snippets/test_logging.py @@ -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()) + diff --git a/vm/src/obj/objframe.rs b/vm/src/obj/objframe.rs index 6669e3bb9..73f4e9b91 100644 --- a/vm/src/obj/objframe.rs +++ b/vm/src/obj/objframe.rs @@ -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 { "".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()) + } }