Commit f62dad2f by Will Daly Committed by Ned Batchelder

Added symbolic response tests

parent e61a6fe7
...@@ -46,7 +46,7 @@ import sys ...@@ -46,7 +46,7 @@ import sys
import pyparsing import pyparsing
from .registry import TagRegistry from .registry import TagRegistry
from capa.chem import chemcalc from chem import chemcalc
import xqueue_interface import xqueue_interface
from datetime import datetime from datetime import datetime
......
...@@ -29,7 +29,7 @@ from collections import namedtuple ...@@ -29,7 +29,7 @@ from collections import namedtuple
from shapely.geometry import Point, MultiPoint from shapely.geometry import Point, MultiPoint
# specific library imports # specific library imports
from .calc import evaluator, UndefinedVariable from calc import evaluator, UndefinedVariable
from .correctmap import CorrectMap from .correctmap import CorrectMap
from datetime import datetime from datetime import datetime
from .util import * from .util import *
...@@ -1043,7 +1043,7 @@ class CustomResponse(LoncapaResponse): ...@@ -1043,7 +1043,7 @@ class CustomResponse(LoncapaResponse):
messages = self.context['messages'] messages = self.context['messages']
correct_map = CorrectMap() correct_map = CorrectMap()
overall_message = self.clean_message_html(self.context['overall_message'])) overall_message = self.clean_message_html(self.context['overall_message'])
correct_map.set_overall_message(overall_message) correct_map.set_overall_message(overall_message)
for k in range(len(idset)): for k in range(len(idset)):
...@@ -1195,12 +1195,24 @@ class SymbolicResponse(CustomResponse): ...@@ -1195,12 +1195,24 @@ class SymbolicResponse(CustomResponse):
""" """
response_tag = 'symbolicresponse' response_tag = 'symbolicresponse'
max_inputfields = 1
def setup_response(self):
# Symbolic response always uses symmath_check()
# If the XML did not specify this, then set it now
# Otherwise, we get an error from the superclass
self.xml.set('cfn', 'symmath_check')
# Let CustomResponse do its setup
super(SymbolicResponse, self).setup_response()
def execute_check_function(self, idset, submission): def execute_check_function(self, idset, submission):
from symmath import symmath_check from symmath import symmath_check
fn = self.code
try: try:
answer_given = submission[0] if (len(idset) == 1) else submission # Since we have limited max_inputfields to 1,
# we can assume that there is only one submission
answer_given = submission[0]
ret = symmath_check( ret = symmath_check(
self.expect, answer_given, self.expect, answer_given,
dynamath=self.context.get('dynamath'), dynamath=self.context.get('dynamath'),
......
...@@ -734,3 +734,38 @@ class AnnotationResponseXMLFactory(ResponseXMLFactory): ...@@ -734,3 +734,38 @@ class AnnotationResponseXMLFactory(ResponseXMLFactory):
option_element.text = description option_element.text = description
return input_element return input_element
class SymbolicResponseXMLFactory(ResponseXMLFactory):
""" Factory for producing <symbolicresponse> xml """
def create_response_element(self, **kwargs):
""" Build the <symbolicresponse> XML element.
Uses **kwargs:
*expect*: The correct answer (a sympy string)
*options*: list of option strings to pass to symmath_check
(e.g. 'matrix', 'qbit', 'imaginary', 'numerical')"""
# Retrieve **kwargs
expect = kwargs.get('expect', '')
options = kwargs.get('options', [])
# Symmath check expects a string of options
options_str = ",".join(options)
# Construct the <symbolicresponse> element
response_element = etree.Element('symbolicresponse')
if expect:
response_element.set('expect', str(expect))
if options_str:
response_element.set('options', str(options_str))
return response_element
def create_input_element(self, **kwargs):
return ResponseXMLFactory.textline_input_xml(**kwargs)
from .calc import evaluator, UndefinedVariable from calc import evaluator
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment