本文整理汇总了Python中console.Console.get_locals方法的典型用法代码示例。如果您正苦于以下问题:Python Console.get_locals方法的具体用法?Python Console.get_locals怎么用?Python Console.get_locals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类console.Console
的用法示例。
在下文中一共展示了Console.get_locals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_script
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import get_locals [as 别名]
def execute_script(script, test_code, extra_locals, files):
soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
resource.setrlimit(resource.RLIMIT_CPU, (10, hard))
checker = Console(locals_=extra_locals, files=files)
feedback = checker.run_tests(script, test_code)
output = checker.output
return_code = 0
if feedback:
return_code = 1
new_locals = checker.get_locals()
resource.setrlimit(resource.RLIMIT_CPU, (soft, hard))
return return_code, output, feedback, new_locals
示例2: test_saves_fp_on_locals
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import get_locals [as 别名]
def test_saves_fp_on_locals(self):
files = {'dummy.txt': 'oi'}
console = Console(files=files)
code = "fd = open('dummy.txt')"
console.run_tests(code, TEST_CODE)
locals_ = console.get_locals()
json_data = pickle.dumps(locals_)
new_locals = pickle.loads(json_data)
console = Console(locals_=new_locals)
code = "print fd.read()"
console.run_tests(code, TEST_CODE)
self.assertEqual('oi\n', console.output)