def __init__(self, files=None, main_file='answer.py', main_code=None, user=None, assignment=None, course=None, execution=None, instructor_file='on_run.py', skip_tifa=False, set_success=True, report=MAIN_REPORT): # Possibly user passed in stuff via the command line. if files is None and main_code is None: (instructor_file, files, main_file, main_code, user, assignment, course, execution) = parse_argv() super().__init__(files=files, main_file=main_file, main_code=main_code, user=user, assignment=assignment, course=course, execution=execution, instructor_file=instructor_file, report=report) # Then default custom stuff verify(report=report) self.ast = parse_program(report=report) if skip_tifa: self.tifa = None else: from pedal.tifa import tifa_analysis self.tifa = tifa_analysis(report=report) self.student = run(threaded=True, report=report) self.set_success = set_success
def test_unmessaged_tifa(self): clear_report() contextualize_report('import random\nrandom') verify() tifa_analysis() final = simple.resolve() self.assertEqual(SUCCESS_MESSAGE, final.title+"\n"+final.message)
def test_hidden_error(self): clear_report() contextualize_report('import pedal') verify() tifa_analysis() final = simple.resolve() self.assertNotEqual("No errors reported.", final.message)
def test_success_suppression(self): clear_report() contextualize_report('a=0\na') verify() tifa_analysis() set_success() suppress(label='set_success') final = simple.resolve() self.assertEqual(Feedback.CATEGORIES.COMPLETE, final.category) self.assertEqual(SUCCESS_MESSAGE, final.title+"\n"+final.message)
def test_empty(self): clear_report() contextualize_report(' ') verify() tifa_analysis() commands.run() final = simple.resolve() self.assertEqual(Feedback.CATEGORIES.SYNTAX, final.category) self.assertEqual("No Source Code", final.title) self.assertEqual("Source code file is blank.", final.message)
def test_success(self): clear_report() contextualize_report('a=0\na') verify() tifa_analysis() set_success() final = simple.resolve() self.assertEqual(Feedback.CATEGORIES.COMPLETE, final.category) self.assertEqual("Complete", final.title) self.assertEqual("Great work!", final.message)
def test_runtime_suppression(self): clear_report() contextualize_report('import json\njson.loads("0")+"1"') verify() tifa_analysis() commands.run() suppress("Runtime") final = simple.resolve() self.assertEqual(Feedback.CATEGORIES.COMPLETE, final.category) self.assertEqual(SUCCESS_TEXT, final.message)
def test_analyzer_suppression(self): clear_report() contextualize_report('1+"Hello"') verify() tifa_analysis() commands.run() suppress("analyzer") final = simple.resolve() self.assertEqual("runtime", final.category) self.assertEqual("Type Error", final.title)
def to_source(source): """ Args: source: """ MAIN_REPORT.clear() contextualize_report(source) verify() parse_program() tifa_analysis()
def __enter__(self): clear_report(report=self.report) contextualize_report(self.code, report=self.report) verify(report=self.report) if self.run_tifa: tifa_analysis(report=self.report) # TODO: Clean this up self.student = get_sandbox(self.report) self.report['sandbox']['sandbox'].tracer_style = self.tracer_style commands.run() return self
def __init__(self, files=None, main_file='answer.py', main_code=None, user=None, assignment=None, course=None, execution=None, instructor_file='on_run.py', skip_tifa=False, skip_run=False, inputs=None, set_success=True, report=MAIN_REPORT, trace=True, threaded=True, **kwargs): super().__init__(files=files, main_file=main_file, main_code=main_code, user=user, assignment=assignment, course=course, execution=execution, instructor_file=instructor_file, report=report) self.skip_run = skip_run self.skip_tifa = skip_tifa self.trace = trace report.set_formatter(Formatter(report)) verify(report=self.report) if not skip_tifa: tifa_analysis(report=self.report) if inputs: set_input(inputs) if skip_run: student = get_sandbox(report=report) student.threaded = threaded else: if trace: start_trace() student = run(report=report, threaded=threaded) student.threaded = threaded self.fields = { 'student': student, 'resolve': resolve, 'next_section': self.next_section, 'sectional_resolve': sectional_resolve, 'show_as_hidden': show_as_hidden }
def next_section(self, name=""): original_next_section(name=name, report=self.report) verify(report=self.report) if not self.skip_tifa: tifa_analysis(report=self.report) student = get_sandbox(report=self.report) if self.skip_run: student.clear() else: if self.trace: start_trace() student.clear() student = student.run() return student
def test_gently_vs_runtime(self): # Runtime > Gently clear_report() contextualize_report('import json\njson.loads("0")+"1"') verify() tifa_analysis() commands.run() gently("I have a gentle opinion, but you don't want to hear it.") final = simple.resolve() print(final.label) self.assertEqual(Feedback.CATEGORIES.RUNTIME, final.category) # Runtime < Explain clear_report() contextualize_report('import json\njson.loads("0")+"1"') verify() tifa_analysis() commands.run() explain("LISTEN TO ME") final = simple.resolve() self.assertEqual(Feedback.CATEGORIES.INSTRUCTOR, final.category)
def test_sectional_success(self): clear_report() contextualize_report('a=0\n##### Part 1\nprint("A")\n##### Part 2\nprint("B")') separate_into_sections(independent=True) # Part 0 verify() commands.clear_sandbox() commands.run() # Part 1 next_section() verify() commands.clear_sandbox() commands.run() give_partial(.2) # Part 2 next_section() verify() commands.clear_sandbox() commands.run() give_partial(.2) # Resolve everything finals = sectional.resolve() self.assertEqual("""# Global FeedbackSourceSection Feedback separated into groups # 1 Complete Great work! # 2 Complete Great work!""", "\n".join(f"# {g.section_number if g is not None else 'Global'}\n{f.title}\n{f.message}" for g, f in finals.items()))
def test_sectional_error(self): clear_report() contextualize_report('a=0\n##### Part 1\nprint("A")\n##### Part 2\nsyntax error') separate_into_sections(independent=True) # Part 0 verify() commands.clear_sandbox() commands.run() # Part 1 next_section() verify() commands.clear_sandbox() commands.run() give_partial(.2) # Part 2 next_section() verify() commands.clear_sandbox() commands.run() give_partial(.2) # Resolve everything finals = sectional.resolve() self.assertEqual("""# Global FeedbackSourceSection Feedback separated into groups # 1 Complete Great work! # 2 Syntax Error Bad syntax on line 5 The traceback was: Line 5 of file answer.py syntax error Suggestion: Check line 5, the line before it, and the line after it.""", "\n".join(f"# {g.section_number if g is not None else 'Global'}\n{f.title}\n{f.message}" for g, f in finals.items()))
def test_broken_traversal(self): contextualize_report("user entered gobblydegook") verify() parse = parse_program() self.assertFalse(parse.find_all('For'))