Skip to content

Commit 89d5424

Browse files
feat(numericalInput): fix input types tests
1 parent 83a39a8 commit 89d5424

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

xmodule/capa/inputtypes.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,15 +1302,20 @@ def preview_formcalc(self, get):
13021302
# TODO add references to valid variables and functions
13031303
# At some point, we might want to mark invalid variables as red
13041304
# or something, and this is where we would need to pass those in.
1305-
from xmodule.capa_block import ProblemBlock
1306-
numeric_result = ProblemBlock.preview_numeric_input(formula)
1307-
# Map results into the correct format
1308-
result["preview"] = numeric_result["preview"]
1309-
if numeric_result["error"]:
1310-
result["error"] = numeric_result["error"]
1311-
# if formula is invalid return formula
1312-
if not numeric_result["is_valid"]:
1313-
result["formula"] = formula
1305+
try:
1306+
from xmodule.capa_block import ProblemBlock
1307+
numeric_result = ProblemBlock.preview_numeric_input(formula)
1308+
# Map results into the correct format
1309+
result["preview"] = numeric_result["preview"]
1310+
if numeric_result["error"]:
1311+
result["error"] = numeric_result["error"]
1312+
# if formula is invalid return formula
1313+
if not numeric_result["is_valid"]:
1314+
result["formula"] = formula
1315+
except Exception: # lint-amnesty, pylint: disable=broad-except
1316+
log.warning("Error while previewing formula", exc_info=True)
1317+
result["error"] = _("Error while rendering preview")
1318+
return result
13141319

13151320
return result
13161321

xmodule/capa/tests/test_inputtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ def test_ajax_parse_err(self):
13611361
With parse errors, FormulaEquationInput should give an error message
13621362
"""
13631363
# Simulate answering a problem that raises the exception
1364-
with patch("xmodule.capa.inputtypes.latex_preview") as mock_preview:
1364+
with patch('xmodule.capa_block.ProblemBlock.preview_numeric_input') as mock_preview:
13651365
mock_preview.side_effect = ParseException("Oopsie")
13661366
response = self.the_input.handle_ajax(
13671367
"preview_formcalc",
@@ -1379,7 +1379,7 @@ def test_ajax_other_err(self, mock_log):
13791379
"""
13801380
With other errors, test that FormulaEquationInput also logs it
13811381
"""
1382-
with patch("xmodule.capa.inputtypes.latex_preview") as mock_preview:
1382+
with patch('xmodule.capa_block.ProblemBlock.preview_numeric_input') as mock_preview:
13831383
mock_preview.side_effect = Exception()
13841384
response = self.the_input.handle_ajax(
13851385
"preview_formcalc",

0 commit comments

Comments
 (0)