def define_code_response_problem(self, problem_url_name): """ Define an arbitrary code-response problem. We'll end up mocking its evaluation later. """ factory = CodeResponseXMLFactory() grader_payload = json.dumps({"grader": "ps04/grade_square.py"}) problem_xml = factory.build_xml(initial_display="def square(x):", answer_display="answer", grader_payload=grader_payload, num_responses=2) ItemFactory.create(parent_location=self.problem_section.location, category="problem", display_name=str(problem_url_name), data=problem_xml)
def define_code_response_problem(self, problem_url_name): """ Define an arbitrary code-response problem. We'll end up mocking its evaluation later. """ factory = CodeResponseXMLFactory() grader_payload = json.dumps({"grader": "ps04/grade_square.py"}) problem_xml = factory.build_xml(initial_display="def square(x):", answer_display="answer", grader_payload=grader_payload, num_responses=2) ItemFactory.create(parent_location=self.problem_section.location, category="problem", display_name=str(problem_url_name), data=problem_xml)
class CodeProblemTypeTest(ProblemTypeTestBase, ProblemTypeTestMixin): """ TestCase Class for Code Problem Type """ problem_name = 'CODE TEST PROBLEM' problem_type = 'code' factory = CodeResponseXMLFactory() factory_kwargs = { 'question_text': 'Submit code to an external grader', 'initial_display': 'print "Hello world!"', 'grader_payload': '{"grader": "ps1/Spring2013/test_grader.py"}', } status_indicators = { 'correct': ['.grader-status .correct ~ .debug'], 'incorrect': ['.grader-status .incorrect ~ .debug'], 'unanswered': ['.grader-status .unanswered ~ .debug'], } def setUp(self, *args, **kwargs): """ Additional setup for CodeProblemTypeTest """ super(CodeProblemTypeTest, self).setUp(*args, **kwargs) self.problem_page.a11y_audit.config.set_rules({ 'ignore': [ 'color-contrast', # TODO: AC-286 'label', # TODO: AC-286 ] }) def answer_problem(self, correct): """ Answer code problem. """ # The fake xqueue server is configured to respond # correct / incorrect no matter what we submit. # Furthermore, since the inline code response uses # JavaScript to make the code display nicely, it's difficult # to programatically input text # (there's not <textarea> we can just fill text into) # For this reason, we submit the initial code in the response # (configured in the problem XML above) pass def test_answer_incorrectly(self): """ Overridden for script test because the testing grader always responds with "correct" """ pass def test_submit_blank_answer(self): """ Overridden for script test because the testing grader always responds with "correct" """ pass
def problem_setup(self, name, files): """ Create a CodeResponse problem with files to upload. """ xmldata = CodeResponseXMLFactory().build_xml( allowed_files=files, required_files=files, ) ItemFactory.create(parent_location=self.section.location, category='problem', display_name=name, data=xmldata) # re-fetch the course from the database so the object is up to date self.refresh_course()
class CodeProblemTypeBase(ProblemTypeTestBase): """ ProblemTypeTestBase specialization for Code Problem Type """ problem_name = 'CODE TEST PROBLEM' problem_type = 'code' partially_correct = False can_update_save_notification = False factory = CodeResponseXMLFactory() factory_kwargs = { 'question_text': 'Submit code to an external grader', 'initial_display': 'print "Hello world!"', 'grader_payload': '{"grader": "ps1/Spring2013/test_grader.py"}', } status_indicators = { 'correct': ['.grader-status .correct ~ .debug'], 'incorrect': ['.grader-status .incorrect ~ .debug'], 'unanswered': ['.grader-status .unanswered ~ .debug'], 'submitted': ['.grader-status .submitted ~ .debug'], } def answer_problem(self, correctness): """ Answer code problem. """ # The fake xqueue server is configured to respond # correct / incorrect no matter what we submit. # Furthermore, since the inline code response uses # JavaScript to make the code display nicely, it's difficult # to programatically input text # (there's not <textarea> we can just fill text into) # For this reason, we submit the initial code in the response # (configured in the problem XML above) pass
def test_add_to_ten(expect,ans): try: a1=int(ans[0]) a2=int(ans[1]) except ValueError: a1=0 a2=0 return (a1+a2)==int(expect) """) }, 'correct': ['div.correct'], 'incorrect': ['div.incorrect'], 'unanswered': ['div.unanswered'] }, 'code': { 'factory': CodeResponseXMLFactory(), 'kwargs': { 'question_text': 'Submit code to an external grader', 'initial_display': 'print "Hello world!"', 'grader_payload': '{"grader": "ps1/Spring2013/test_grader.py"}', }, 'correct': ['span.correct'], 'incorrect': ['span.incorrect'], 'unanswered': ['span.unanswered'] }, 'radio_text': { 'factory': ChoiceTextResponseXMLFactory(), 'kwargs': { 'question_text': 'The correct answer is Choice 0 and input 8', 'type':