Пример #1
0
def run(raise_exceptions=True,
        report=None,
        coverage=False,
        threaded=False,
        inputs=None):
    if report is None:
        report = MAIN_REPORT
    if 'run' not in report['sandbox']:
        report['sandbox']['run'] = Sandbox(
            filename=report['source']['filename'], threaded=threaded)
    sandbox = report['sandbox']['run']
    source_code = report['source']['code']
    sandbox.record_coverage = coverage
    sandbox.run(source_code,
                _as_filename=report['source']['filename'],
                _inputs=inputs)
    if raise_exceptions and sandbox.exception is not None:
        name = str(sandbox.exception.__class__)[8:-2]
        report.attach(name,
                      category='Runtime',
                      tool='Sandbox',
                      section=report['source']['section'],
                      mistakes={
                          'message': sandbox.format_exception(),
                          'error': sandbox.exception
                      })
    return sandbox
Пример #2
0
def reset(report=MAIN_REPORT):
    """
    Resets (or initializes) the Sandbox instance for this report.
    Completely destroys the existing Sandbox instance attached to this report;
    if you want to just clear out its data, then instead use
    :py:func:`pedal.sandbox.commands.clear_sandbox`.

    Args:
        report:
    """
    report[TOOL_NAME] = {'sandbox': Sandbox(report=report)}
Пример #3
0
def reset(report=None):
    if report is None:
        report = MAIN_REPORT
    report['sandbox']['run'] = Sandbox(filename=report['source']['filename'])
Пример #4
0
import sys

from pedal.report import *
from pedal.source import set_source
set_source("1+''", "answer.py")

from pedal.sandbox.sandbox import Sandbox
from pedal.sandbox import compatibility

student = MAIN_REPORT['sandbox']['run'] = Sandbox()

student.report_exceptions_mode = True
print(len(sys.modules.keys()), sorted(sys.modules.keys()))
old = set(sys.modules.keys())
compatibility.run_student(raise_exceptions=True)

#import pedal.mistakes.instructor_append as ins_app

#print(ins_app)

from pedal.mistakes import instructor_append

new = set(sys.modules.keys())
print(len(sys.modules.keys()), sorted(sys.modules.keys()))

print(new - old)

print(student.output)
print(student.exception_position)

from pedal.resolvers import simple
Пример #5
0
def _check_sandbox(report):
    if 'run' not in report['sandbox']:
        report['sandbox']['run'] = Sandbox()
    return report['sandbox']['run']