def test_compatibility_api(self): student_code = 'word = input("Give me a word")\nprint(word+"!")' set_source(student_code) self.assertFalse(compatibility.get_output()) compatibility.queue_input("Hello") self.assertIsNone(compatibility.run_student()) self.assertEqual(compatibility.get_output(), ["Give me a word", "Hello!"]) compatibility.queue_input("World", "Again") self.assertIsNone(compatibility.run_student()) self.assertEqual( compatibility.get_output(), ["Give me a word", "Hello!", "Give me a word", "World!"]) self.assertIsNone(compatibility.run_student()) self.assertEqual(compatibility.get_output(), [ "Give me a word", "Hello!", "Give me a word", "World!", "Give me a word", "Again!" ]) compatibility.reset_output() compatibility.queue_input("Dogs", "Are", "Great") self.assertIsNone(compatibility.run_student()) self.assertIsNone(compatibility.run_student()) self.assertIsNone(compatibility.run_student()) self.assertEqual(compatibility.get_output(), [ "Give me a word", "Dogs!", "Give me a word", "Are!", "Give me a word", "Great!" ])
def test_matplotlib_compatibility(self): student_code = dedent(''' import matplotlib.pyplot as plt plt.plot([1,2,3]) plt.title("My line plot") plt.show() plt.hist([1,2,3]) plt.show() ''') set_source(student_code) exception = compatibility.run_student() plt2 = compatibility.get_plots() self.assertEqual(len(plt2), 2)
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
import sys from pedal.report import * from pedal.source import set_source set_source( """ import matplotlib.pyplot as plt print("Hello world") plt.hist([1,2,3]) plt.xlabel("Hello") plt.show() """, "answer.py") from pedal.sandbox.sandbox import Sandbox from pedal.sandbox import compatibility student = MAIN_REPORT['sandbox']['run'] = Sandbox() student.report_exceptions_mode = True compatibility.run_student(raise_exceptions=False) print(compatibility.get_output()) print(compatibility.get_plots()) from pedal.resolvers import simple SUCCESS, SCORE, CATEGORY, LABEL, MESSAGE, DATA, HIDE = simple.resolve() print(CATEGORY, LABEL, MESSAGE)
def __enter__(self): clear_report() set_source(self.code) tifa_analysis() compatibility.run_student(raise_exceptions=True) return self
def test_compatibility_exceptions(self): student_code = '1 + "Banana"' set_source(student_code) exception = compatibility.run_student() self.assertIsNotNone(exception)