diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py
index aa507a5281..5a89b69136 100644
--- a/common/lib/capa/capa/inputtypes.py
+++ b/common/lib/capa/capa/inputtypes.py
@@ -150,8 +150,8 @@ class InputTypeBase(object):
## we can swap this around in the future if there's a more logical
## order.
- self.id = state.get('id', xml.get('id'))
- if self.id is None:
+ self.input_id = state.get('id', xml.get('id'))
+ if self.input_id is None:
raise ValueError("input id state is None. xml is {0}".format(
etree.tostring(xml)))
@@ -249,7 +249,7 @@ class InputTypeBase(object):
and don't need to override this method.
"""
context = {
- 'id': self.id,
+ 'id': self.input_id,
'value': self.value,
'status': self.status,
'msg': self.msg,
@@ -457,20 +457,20 @@ class TextLine(InputTypeBase):
"""
A text line input. Can do math preview if "math"="1" is specified.
- If "trailing_text" is set to a value, then the textline will be shown with
- the value after the text input, and before the checkmark or any input-specific
- feedback. HTML will not work, but properly escaped HTML characters will. This
- feature is useful if you would like to specify a specific type of units for the
+ If "trailing_text" is set to a value, then the textline will be shown with
+ the value after the text input, and before the checkmark or any input-specific
+ feedback. HTML will not work, but properly escaped HTML characters will. This
+ feature is useful if you would like to specify a specific type of units for the
text input.
- If the hidden attribute is specified, the textline is hidden and the input id
- is stored in a div with name equal to the value of the hidden attribute. This
+ If the hidden attribute is specified, the textline is hidden and the input id
+ is stored in a div with name equal to the value of the hidden attribute. This
is used e.g. for embedding simulations turned into questions.
Example:
- This example will render out a text line with a math preview and the text 'm/s'
+ This example will render out a text line with a math preview and the text 'm/s'
after the end of the text line.
"""
@@ -623,7 +623,6 @@ class CodeInput(InputTypeBase):
self.queue_len = self.msg
self.msg = self.submitted_msg
-
def setup(self):
''' setup this input type '''
self.setup_code_response_rendering()
@@ -655,7 +654,7 @@ class MatlabInput(CodeInput):
tags = ['matlabinput']
plot_submitted_msg = ("Submitted. As soon as a response is returned, "
- "this message will be replaced by that feedback.")
+ "this message will be replaced by that feedback.")
def setup(self):
'''
@@ -676,16 +675,16 @@ class MatlabInput(CodeInput):
self.queue_len = 1
self.msg = self.plot_submitted_msg
-
def handle_ajax(self, dispatch, get):
- '''
+ '''
Handle AJAX calls directed to this input
Args:
- dispatch (str) - indicates how we want this ajax call to be handled
- get (dict) - dictionary of key-value pairs that contain useful data
Returns:
-
+ dict - 'success' - whether or not we successfully queued this submission
+ - 'message' - message to be rendered in case of error
'''
if dispatch == 'plot':
@@ -693,7 +692,7 @@ class MatlabInput(CodeInput):
return {}
def ungraded_response(self, queue_msg, queuekey):
- '''
+ '''
Handle the response from the XQueue
Stores the response in the input_state so it can be rendered later
@@ -705,7 +704,7 @@ class MatlabInput(CodeInput):
nothing
'''
# check the queuekey against the saved queuekey
- if('queuestate' in self.input_state and self.input_state['queuestate'] == 'queued'
+ if('queuestate' in self.input_state and self.input_state['queuestate'] == 'queued'
and self.input_state['queuekey'] == queuekey):
msg = self._parse_data(queue_msg)
# save the queue message so that it can be rendered later
@@ -716,9 +715,9 @@ class MatlabInput(CodeInput):
def _extra_context(self):
''' Set up additional context variables'''
extra_context = {
- 'queue_len': str(self.queue_len),
- 'queue_msg': self.queue_msg
- }
+ 'queue_len': str(self.queue_len),
+ 'queue_msg': self.queue_msg
+ }
return extra_context
def _parse_data(self, queue_msg):
@@ -733,20 +732,19 @@ class MatlabInput(CodeInput):
result = json.loads(queue_msg)
except (TypeError, ValueError):
log.error("External message should be a JSON serialized dict."
- " Received queue_msg = %s" % queue_msg)
+ " Received queue_msg = %s" % queue_msg)
raise
msg = result['msg']
return msg
-
def _plot_data(self, get):
- '''
+ '''
AJAX handler for the plot button
Args:
get (dict) - should have key 'submission' which contains the student submission
Returns:
dict - 'success' - whether or not we successfully queued this submission
- - 'message' - message to be rendered in case of error
+ - 'message' - message to be rendered in case of error
'''
# only send data if xqueue exists
if self.system.xqueue is None:
@@ -762,26 +760,25 @@ class MatlabInput(CodeInput):
anonymous_student_id = self.system.anonymous_student_id
queuekey = xqueue_interface.make_hashkey(str(self.system.seed) + qtime +
anonymous_student_id +
- self.id)
+ self.input_id)
xheader = xqueue_interface.make_xheader(
- lms_callback_url = callback_url,
- lms_key = queuekey,
- queue_name = self.queuename)
+ lms_callback_url=callback_url,
+ lms_key=queuekey,
+ queue_name=self.queuename)
# save the input state
self.input_state['queuekey'] = queuekey
self.input_state['queuestate'] = 'queued'
-
# construct xqueue body
student_info = {'anonymous_student_id': anonymous_student_id,
- 'submission_time': qtime}
+ 'submission_time': qtime}
contents = {'grader_payload': self.plot_payload,
'student_info': json.dumps(student_info),
'student_response': response}
(error, msg) = qinterface.send_to_queue(header=xheader,
- body = json.dumps(contents))
+ body=json.dumps(contents))
return {'success': error == 0, 'message': msg}
@@ -1040,7 +1037,7 @@ class DragAndDropInput(InputTypeBase):
if tag_type == 'draggable':
dic['target_fields'] = [parse(target, 'target') for target in
- tag.iterchildren('target')]
+ tag.iterchildren('target')]
return dic
diff --git a/common/lib/capa/capa/tests/test_inputtypes.py b/common/lib/capa/capa/tests/test_inputtypes.py
index 7e2f956f56..d461a5e82c 100644
--- a/common/lib/capa/capa/tests/test_inputtypes.py
+++ b/common/lib/capa/capa/tests/test_inputtypes.py
@@ -60,6 +60,7 @@ class OptionInputTest(unittest.TestCase):
def test_option_parsing(self):
f = inputtypes.OptionInput.parse_options
+
def check(input, options):
"""Take list of options, confirm that output is in the silly doubled format"""
expected = [(o, o) for o in options]
@@ -120,7 +121,6 @@ class ChoiceGroupTest(unittest.TestCase):
self.check_group('checkboxgroup', 'checkbox', '[]')
-
class JavascriptInputTest(unittest.TestCase):
'''
The javascript input is a pretty straightforward pass-thru, but test it anyway
@@ -186,7 +186,6 @@ class TextLineTest(unittest.TestCase):
'preprocessor': None}
self.assertEqual(context, expected)
-
def test_math_rendering(self):
size = "42"
preprocessorClass = "preParty"
@@ -226,11 +225,11 @@ class TextLineTest(unittest.TestCase):
trailing_text.append((u'\xc3', u'\xc3'))
# html escaped trailing text
# this is the only one we expect to change
- trailing_text.append(('a < b','a < b'))
+ trailing_text.append(('a < b', 'a < b'))
for xml_text, expected_text in trailing_text:
- xml_str = u"""""".format(size=size, tt=xml_text)
@@ -269,7 +268,6 @@ class FileSubmissionTest(unittest.TestCase):
/>""".format(af=allowed_files,
rf=required_files,)
-
element = etree.fromstring(xml_str)
state = {'value': 'BumbleBee.py',
@@ -281,12 +279,12 @@ class FileSubmissionTest(unittest.TestCase):
context = the_input._get_render_context()
expected = {'id': 'prob_1_2',
- 'status': 'queued',
- 'msg': input_class.submitted_msg,
- 'value': 'BumbleBee.py',
- 'queue_len': '3',
- 'allowed_files': '["runme.py", "nooooo.rb", "ohai.java"]',
- 'required_files': '["cookies.py"]'}
+ 'status': 'queued',
+ 'msg': input_class.submitted_msg,
+ 'value': 'BumbleBee.py',
+ 'queue_len': '3',
+ 'allowed_files': '["runme.py", "nooooo.rb", "ohai.java"]',
+ 'required_files': '["cookies.py"]'}
self.assertEqual(context, expected)
@@ -327,19 +325,19 @@ class CodeInputTest(unittest.TestCase):
expected = {'id': 'prob_1_2',
'value': 'print "good evening"',
- 'status': 'queued',
- 'msg': input_class.submitted_msg,
- 'mode': mode,
- 'linenumbers': linenumbers,
- 'rows': rows,
- 'cols': cols,
- 'hidden': '',
- 'tabsize': int(tabsize),
- 'queue_len': '3',
- }
+ 'status': 'queued',
+ 'msg': input_class.submitted_msg,
+ 'mode': mode,
+ 'linenumbers': linenumbers,
+ 'rows': rows,
+ 'cols': cols,
+ 'hidden': '',
+ 'tabsize': int(tabsize),
+ 'queue_len': '3'}
self.assertEqual(context, expected)
+
class MatlabTest(unittest.TestCase):
'''
Test Matlab input types
@@ -352,18 +350,18 @@ class MatlabTest(unittest.TestCase):
self.payload = "payload"
self.linenumbers = 'true'
self.xml = """
{payload}
- """.format(r = self.rows,
- c = self.cols,
- tabsize = self.tabsize,
- m = self.mode,
- payload = self.payload,
- ln = self.linenumbers)
+ """.format(r=self.rows,
+ c=self.cols,
+ tabsize=self.tabsize,
+ m=self.mode,
+ payload=self.payload,
+ ln=self.linenumbers)
elt = etree.fromstring(self.xml)
state = {'value': 'print "good evening"',
'status': 'incomplete',
@@ -372,27 +370,24 @@ class MatlabTest(unittest.TestCase):
self.input_class = lookup_tag('matlabinput')
self.the_input = self.input_class(test_system, elt, state)
-
def test_rendering(self):
context = self.the_input._get_render_context()
expected = {'id': 'prob_1_2',
'value': 'print "good evening"',
- 'status': 'queued',
- 'msg': self.input_class.submitted_msg,
- 'mode': self.mode,
- 'rows': self.rows,
- 'cols': self.cols,
- 'queue_msg': '',
- 'linenumbers': 'true',
- 'hidden': '',
- 'tabsize': int(self.tabsize),
- 'queue_len': '3',
- }
+ 'status': 'queued',
+ 'msg': self.input_class.submitted_msg,
+ 'mode': self.mode,
+ 'rows': self.rows,
+ 'cols': self.cols,
+ 'queue_msg': '',
+ 'linenumbers': 'true',
+ 'hidden': '',
+ 'tabsize': int(self.tabsize),
+ 'queue_len': '3'}
self.assertEqual(context, expected)
-
def test_rendering_with_state(self):
state = {'value': 'print "good evening"',
'status': 'incomplete',
@@ -405,17 +400,16 @@ class MatlabTest(unittest.TestCase):
expected = {'id': 'prob_1_2',
'value': 'print "good evening"',
- 'status': 'queued',
- 'msg': self.input_class.submitted_msg,
- 'mode': self.mode,
- 'rows': self.rows,
- 'cols': self.cols,
- 'queue_msg': 'message',
- 'linenumbers': 'true',
- 'hidden': '',
- 'tabsize': int(self.tabsize),
- 'queue_len': '3',
- }
+ 'status': 'queued',
+ 'msg': self.input_class.submitted_msg,
+ 'mode': self.mode,
+ 'rows': self.rows,
+ 'cols': self.cols,
+ 'queue_msg': 'message',
+ 'linenumbers': 'true',
+ 'hidden': '',
+ 'tabsize': int(self.tabsize),
+ 'queue_len': '3'}
self.assertEqual(context, expected)
@@ -430,17 +424,16 @@ class MatlabTest(unittest.TestCase):
context = the_input._get_render_context()
expected = {'id': 'prob_1_2',
'value': 'print "good evening"',
- 'status': 'queued',
- 'msg': self.input_class.plot_submitted_msg,
- 'mode': self.mode,
- 'rows': self.rows,
- 'cols': self.cols,
- 'queue_msg': '',
- 'linenumbers': 'true',
- 'hidden': '',
- 'tabsize': int(self.tabsize),
- 'queue_len': '1',
- }
+ 'status': 'queued',
+ 'msg': self.input_class.plot_submitted_msg,
+ 'mode': self.mode,
+ 'rows': self.rows,
+ 'cols': self.cols,
+ 'queue_msg': '',
+ 'linenumbers': 'true',
+ 'hidden': '',
+ 'tabsize': int(self.tabsize),
+ 'queue_len': '1'}
self.assertEqual(context, expected)
@@ -449,7 +442,7 @@ class MatlabTest(unittest.TestCase):
response = self.the_input.handle_ajax("plot", get)
test_system.xqueue['interface'].send_to_queue.assert_called_with(header=ANY, body=ANY)
-
+
self.assertTrue(response['success'])
self.assertTrue(self.the_input.input_state['queuekey'] is not None)
self.assertEqual(self.the_input.input_state['queuestate'], 'queued')
@@ -491,9 +484,6 @@ class MatlabTest(unittest.TestCase):
self.assertFalse('queue_msg' in input_state)
-
-
-
class SchematicTest(unittest.TestCase):
'''
Check that schematic inputs work
@@ -507,7 +497,6 @@ class SchematicTest(unittest.TestCase):
initial_value = 'two large batteries'
submit_analyses = 'maybe'
-
xml_str = """