Skip to content

Commit 8030f82

Browse files
committed
Ed-1879 Remove requests import in symmath
1 parent 25eb318 commit 8030f82

File tree

3 files changed

+2
-83
lines changed

3 files changed

+2
-83
lines changed

common/lib/capa/capa/tests/test_responsetypes.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -308,34 +308,6 @@ def test_show_answer(self):
308308
class SymbolicResponseTest(ResponseTest): # pylint: disable=missing-docstring
309309
xml_factory_class = SymbolicResponseXMLFactory
310310

311-
def test_grade_single_input_correct(self):
312-
problem = self.build_problem(math_display=True, expect="2*x+3*y")
313-
314-
# Correct answers
315-
correct_inputs = [
316-
('2x+3y', textwrap.dedent("""
317-
<math xmlns="http://www.w3.org/1998/Math/MathML">
318-
<mstyle displaystyle="true">
319-
<mn>2</mn><mo>*</mo><mi>x</mi><mo>+</mo><mn>3</mn><mo>*</mo><mi>y</mi>
320-
</mstyle></math>"""),
321-
'snuggletex_2x+3y.xml'),
322-
323-
('x+x+3y', textwrap.dedent("""
324-
<math xmlns="http://www.w3.org/1998/Math/MathML">
325-
<mstyle displaystyle="true">
326-
<mi>x</mi><mo>+</mo><mi>x</mi><mo>+</mo><mn>3</mn><mo>*</mo><mi>y</mi>
327-
</mstyle></math>"""),
328-
'snuggletex_x+x+3y.xml'),
329-
]
330-
331-
for (input_str, input_mathml, server_fixture) in correct_inputs:
332-
print "Testing input: {0}".format(input_str)
333-
server_resp = load_fixture(server_fixture)
334-
self._assert_symbolic_grade(
335-
problem, input_str, input_mathml,
336-
'correct', snuggletex_resp=server_resp
337-
)
338-
339311
def test_grade_single_input_incorrect(self):
340312
problem = self.build_problem(math_display=True, expect="2*x+3*y")
341313

@@ -352,23 +324,6 @@ def test_grade_single_input_incorrect(self):
352324
for (input_str, input_mathml) in incorrect_inputs:
353325
self._assert_symbolic_grade(problem, input_str, input_mathml, 'incorrect')
354326

355-
def test_complex_number_grade_correct(self):
356-
problem = self.build_problem(
357-
math_display=True,
358-
expect="[[cos(theta),i*sin(theta)],[i*sin(theta),cos(theta)]]",
359-
options=["matrix", "imaginary"]
360-
)
361-
362-
correct_snuggletex = load_fixture('snuggletex_correct.html')
363-
dynamath_input = load_fixture('dynamath_input.txt')
364-
student_response = "cos(theta)*[[1,0],[0,1]] + i*sin(theta)*[[0,1],[1,0]]"
365-
366-
self._assert_symbolic_grade(
367-
problem, student_response, dynamath_input,
368-
'correct',
369-
snuggletex_resp=correct_snuggletex
370-
)
371-
372327
def test_complex_number_grade_incorrect(self):
373328

374329
problem = self.build_problem(math_display=True,

common/lib/symmath/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="symmath",
5-
version="0.1",
5+
version="0.2",
66
packages=["symmath"],
77
install_requires=[
88
"sympy==0.7.1",

common/lib/symmath/symmath/formula.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from copy import deepcopy
2222
from xml.sax.saxutils import unescape
2323

24-
import requests
2524
import sympy
2625
from lxml import etree
2726
from sympy import latex, sympify
@@ -428,10 +427,7 @@ def get_content_mathml(self):
428427
return "<html>Error! Cannot process pmathml</html>"
429428
pmathml = etree.tostring(xml, pretty_print=True)
430429
self.the_pmathml = pmathml # pylint: disable=attribute-defined-outside-init
431-
432-
# convert to cmathml
433-
self.the_cmathml = self.GetContentMathML(self.asciimath, pmathml)
434-
return self.the_cmathml
430+
return self.the_pmathml
435431

436432
cmathml = property(get_content_mathml, None, None, 'content MathML representation')
437433

@@ -586,35 +582,3 @@ def parse_presentation_symbol(xml):
586582
raise Exception('[formula] unknown tag %s' % tag)
587583

588584
sympy = property(make_sympy, None, None, 'sympy representation')
589-
590-
def GetContentMathML(self, asciimath, mathml): # pylint: disable=invalid-name
591-
"""
592-
Handle requests to snuggletex API to convert the Ascii math to MathML
593-
"""
594-
url = 'https://math-xserver.mitx.mit.edu/snuggletex-webapp-1.2.2/ASCIIMathMLUpConversionDemo'
595-
596-
payload = {
597-
'asciiMathInput': asciimath,
598-
'asciiMathML': mathml,
599-
}
600-
headers = {
601-
'User-Agent': "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13"
602-
}
603-
request = requests.post(url, data=payload, headers=headers, verify=False)
604-
request.encoding = 'utf-8'
605-
ret = request.text
606-
607-
mode = 0
608-
cmathml = []
609-
for k in ret.split('\n'):
610-
if 'conversion to Content MathML' in k:
611-
mode = 1
612-
continue
613-
if mode == 1:
614-
if '<h3>Maxima Input Form</h3>' in k:
615-
mode = 0
616-
continue
617-
cmathml.append(k)
618-
cmathml = '\n'.join(cmathml[2:])
619-
cmathml = '<math xmlns="http://www.w3.org/1998/Math/MathML">\n' + unescape(cmathml) + '\n</math>'
620-
return cmathml

0 commit comments

Comments
 (0)