Commit d4536c65 by Diana Huang

Merge pull request #1852 from MITx/feature/diana/textline-trailing

Pylint and Pep8 fixes for InputTypes
parents 13aed417 ff1189c5
......@@ -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,
......@@ -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()
......@@ -676,7 +675,6 @@ 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
......@@ -685,7 +683,8 @@ class MatlabInput(CodeInput):
- 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':
......@@ -738,7 +737,6 @@ class MatlabInput(CodeInput):
msg = result['msg']
return msg
def _plot_data(self, get):
'''
AJAX handler for the plot button
......@@ -762,17 +760,16 @@ 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}
......@@ -781,7 +778,7 @@ class MatlabInput(CodeInput):
'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}
......
......@@ -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,7 +225,7 @@ 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 &lt; b','a < b'))
trailing_text.append(('a &lt; b', 'a < b'))
for xml_text, expected_text in trailing_text:
xml_str = u"""<textline id="prob_1_2"
......@@ -269,7 +268,6 @@ class FileSubmissionTest(unittest.TestCase):
/>""".format(af=allowed_files,
rf=required_files,)
element = etree.fromstring(xml_str)
state = {'value': 'BumbleBee.py',
......@@ -335,11 +333,11 @@ class CodeInputTest(unittest.TestCase):
'cols': cols,
'hidden': '',
'tabsize': int(tabsize),
'queue_len': '3',
}
'queue_len': '3'}
self.assertEqual(context, expected)
class MatlabTest(unittest.TestCase):
'''
Test Matlab input types
......@@ -358,12 +356,12 @@ class MatlabTest(unittest.TestCase):
<plot_payload>
{payload}
</plot_payload>
</matlabinput>""".format(r = self.rows,
c = self.cols,
tabsize = self.tabsize,
m = self.mode,
payload = self.payload,
ln = self.linenumbers)
</matlabinput>""".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,7 +370,6 @@ 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()
......@@ -387,12 +384,10 @@ class MatlabTest(unittest.TestCase):
'linenumbers': 'true',
'hidden': '',
'tabsize': int(self.tabsize),
'queue_len': '3',
}
'queue_len': '3'}
self.assertEqual(context, expected)
def test_rendering_with_state(self):
state = {'value': 'print "good evening"',
'status': 'incomplete',
......@@ -414,8 +409,7 @@ class MatlabTest(unittest.TestCase):
'linenumbers': 'true',
'hidden': '',
'tabsize': int(self.tabsize),
'queue_len': '3',
}
'queue_len': '3'}
self.assertEqual(context, expected)
......@@ -439,8 +433,7 @@ class MatlabTest(unittest.TestCase):
'linenumbers': 'true',
'hidden': '',
'tabsize': int(self.tabsize),
'queue_len': '1',
}
'queue_len': '1'}
self.assertEqual(context, expected)
......@@ -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 = """<schematic id="prob_1_2"
height="{h}"
width="{w}"
......@@ -537,8 +526,7 @@ class SchematicTest(unittest.TestCase):
'height': height,
'parts': parts,
'analyses': analyses,
'submit_analyses': submit_analyses,
}
'submit_analyses': submit_analyses}
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