Commit ff1189c5 by Diana Huang

Pylint and Pep8 fixes

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