Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7f2d4b

Browse files
committed
Merge pull request openedx#1876 from MITx/diana/matlab-input-updates
Make updates to the MatlabInput InputType
2 parents a1360a2 + 32881ed commit d7f2d4b

File tree

3 files changed

+66
-20
lines changed

3 files changed

+66
-20
lines changed

common/lib/capa/capa/inputtypes.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@ def setup(self):
668668
# Check if problem has been queued
669669
self.queuename = 'matlab'
670670
self.queue_msg = ''
671+
# this is only set if we don't have a graded response
672+
# the graded response takes precedence
671673
if 'queue_msg' in self.input_state and self.status in ['queued', 'incomplete', 'unsubmitted']:
672674
self.queue_msg = self.input_state['queue_msg']
673675
if 'queuestate' in self.input_state and self.input_state['queuestate'] == 'queued':
@@ -712,11 +714,23 @@ def ungraded_response(self, queue_msg, queuekey):
712714
self.input_state['queuestate'] = None
713715
self.input_state['queuekey'] = None
714716

717+
def button_enabled(self):
718+
""" Return whether or not we want the 'Test Code' button visible
719+
720+
Right now, we only want this button to show up when a problem has not been
721+
checked.
722+
"""
723+
if self.status in ['correct', 'incorrect']:
724+
return False
725+
else:
726+
return True
727+
715728
def _extra_context(self):
716729
''' Set up additional context variables'''
717730
extra_context = {
718731
'queue_len': str(self.queue_len),
719-
'queue_msg': self.queue_msg
732+
'queue_msg': self.queue_msg,
733+
'button_enabled': self.button_enabled(),
720734
}
721735
return extra_context
722736

@@ -766,10 +780,6 @@ def _plot_data(self, get):
766780
lms_key=queuekey,
767781
queue_name=self.queuename)
768782

769-
# save the input state
770-
self.input_state['queuekey'] = queuekey
771-
self.input_state['queuestate'] = 'queued'
772-
773783
# construct xqueue body
774784
student_info = {'anonymous_student_id': anonymous_student_id,
775785
'submission_time': qtime}
@@ -779,6 +789,10 @@ def _plot_data(self, get):
779789

780790
(error, msg) = qinterface.send_to_queue(header=xheader,
781791
body=json.dumps(contents))
792+
# save the input state if successful
793+
if error == 0:
794+
self.input_state['queuekey'] = queuekey
795+
self.input_state['queuestate'] = 'queued'
782796

783797
return {'success': error == 0, 'message': msg}
784798

common/lib/capa/capa/templates/matlabinput.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
${queue_msg|n}
3434
</div>
3535

36+
% if button_enabled:
3637
<div class="plot-button">
37-
<input type="button" class="save" name="plot-button" id="plot_${id}" value="Plot" />
38+
<input type="button" class="save" name="plot-button" id="plot_${id}" value="Run Code" />
3839
</div>
40+
%endif
3941

4042
<script>
4143
// Note: We need to make the area follow the CodeMirror for this to work.
@@ -91,7 +93,7 @@
9193
window.location.reload();
9294
}
9395
else {
94-
gentle_alert(problem_elt, msg);
96+
gentle_alert(problem_elt, response.message);
9597
}
9698
}
9799

@@ -102,7 +104,7 @@
102104
{'submission': submission}, plot_callback);
103105
}
104106
else {
105-
gentle_alert(problem_elt, msg);
107+
gentle_alert(problem_elt, response.message);
106108
}
107109
}
108110

common/lib/capa/capa/tests/test_inputtypes.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ def test_rendering(self):
384384
'linenumbers': 'true',
385385
'hidden': '',
386386
'tabsize': int(self.tabsize),
387+
'button_enabled': True,
387388
'queue_len': '3'}
388389

389390
self.assertEqual(context, expected)
@@ -409,10 +410,37 @@ def test_rendering_with_state(self):
409410
'linenumbers': 'true',
410411
'hidden': '',
411412
'tabsize': int(self.tabsize),
413+
'button_enabled': True,
412414
'queue_len': '3'}
413415

414416
self.assertEqual(context, expected)
415417

418+
def test_rendering_when_completed(self):
419+
for status in ['correct', 'incorrect']:
420+
state = {'value': 'print "good evening"',
421+
'status': status,
422+
'input_state': {},
423+
}
424+
elt = etree.fromstring(self.xml)
425+
426+
the_input = self.input_class(test_system, elt, state)
427+
context = the_input._get_render_context()
428+
expected = {'id': 'prob_1_2',
429+
'value': 'print "good evening"',
430+
'status': status,
431+
'msg': '',
432+
'mode': self.mode,
433+
'rows': self.rows,
434+
'cols': self.cols,
435+
'queue_msg': '',
436+
'linenumbers': 'true',
437+
'hidden': '',
438+
'tabsize': int(self.tabsize),
439+
'button_enabled': False,
440+
'queue_len': '0'}
441+
442+
self.assertEqual(context, expected)
443+
416444
def test_rendering_while_queued(self):
417445
state = {'value': 'print "good evening"',
418446
'status': 'incomplete',
@@ -433,6 +461,7 @@ def test_rendering_while_queued(self):
433461
'linenumbers': 'true',
434462
'hidden': '',
435463
'tabsize': int(self.tabsize),
464+
'button_enabled': True,
436465
'queue_len': '1'}
437466

438467
self.assertEqual(context, expected)
@@ -447,6 +476,17 @@ def test_plot_data(self):
447476
self.assertTrue(self.the_input.input_state['queuekey'] is not None)
448477
self.assertEqual(self.the_input.input_state['queuestate'], 'queued')
449478

479+
def test_plot_data_failure(self):
480+
get = {'submission': 'x = 1234;'}
481+
error_message = 'Error message!'
482+
test_system.xqueue['interface'].send_to_queue.return_value = (1, error_message)
483+
response = self.the_input.handle_ajax("plot", get)
484+
self.assertFalse(response['success'])
485+
self.assertEqual(response['message'], error_message)
486+
self.assertTrue('queuekey' not in self.the_input.input_state)
487+
self.assertTrue('queuestate' not in self.the_input.input_state)
488+
test_system.xqueue['interface'].send_to_queue.return_value = (0, 'Success!')
489+
450490
def test_ungraded_response_success(self):
451491
queuekey = 'abcd'
452492
input_state = {'queuekey': queuekey, 'queuestate': 'queued'}
@@ -583,7 +623,6 @@ def test_corrupt_values(self):
583623
self.check('[12 13 14]', 0, 0)
584624

585625

586-
587626
class CrystallographyTest(unittest.TestCase):
588627
'''
589628
Check that crystallography inputs work
@@ -613,8 +652,7 @@ def test_rendering(self):
613652
'status': 'unsubmitted',
614653
'msg': '',
615654
'width': width,
616-
'height': height,
617-
}
655+
'height': height}
618656

619657
self.assertEqual(context, expected)
620658

@@ -654,13 +692,11 @@ def test_rendering(self):
654692
'width': width,
655693
'height': height,
656694
'molecules': molecules,
657-
'geometries': geometries,
658-
}
695+
'geometries': geometries}
659696

660697
self.assertEqual(context, expected)
661698

662699

663-
664700
class ChemicalEquationTest(unittest.TestCase):
665701
'''
666702
Check that chemical equation inputs work.
@@ -674,7 +710,6 @@ def setUp(self):
674710
state = {'value': 'H2OYeah', }
675711
self.the_input = lookup_tag('chemicalequationinput')(test_system, element, state)
676712

677-
678713
def test_rendering(self):
679714
''' Verify that the render context matches the expected render context'''
680715
context = self.the_input._get_render_context()
@@ -688,10 +723,8 @@ def test_rendering(self):
688723
}
689724
self.assertEqual(context, expected)
690725

691-
692726
def test_chemcalc_ajax_sucess(self):
693727
''' Verify that using the correct dispatch and valid data produces a valid response'''
694-
695728
data = {'formula': "H"}
696729
response = self.the_input.handle_ajax("preview_chemcalc", data)
697730

@@ -700,9 +733,6 @@ def test_chemcalc_ajax_sucess(self):
700733
self.assertEqual(response['error'], "")
701734

702735

703-
704-
705-
706736
class DragAndDropTest(unittest.TestCase):
707737
'''
708738
Check that drag and drop inputs work

0 commit comments

Comments
 (0)