Unverified Commit b159c271 by Sofiya Semenova Committed by GitHub

Merge pull request #16864 from edx/sofiya/symmath

Educator-1879 Symmath fails to initialize because of requests library
parents e4648bff 8030f82e
...@@ -308,34 +308,6 @@ class ImageResponseTest(ResponseTest): # pylint: disable=missing-docstring ...@@ -308,34 +308,6 @@ class ImageResponseTest(ResponseTest): # pylint: disable=missing-docstring
class SymbolicResponseTest(ResponseTest): # pylint: disable=missing-docstring class SymbolicResponseTest(ResponseTest): # pylint: disable=missing-docstring
xml_factory_class = SymbolicResponseXMLFactory xml_factory_class = SymbolicResponseXMLFactory
def test_grade_single_input_correct(self):
problem = self.build_problem(math_display=True, expect="2*x+3*y")
# Correct answers
correct_inputs = [
('2x+3y', textwrap.dedent("""
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mn>2</mn><mo>*</mo><mi>x</mi><mo>+</mo><mn>3</mn><mo>*</mo><mi>y</mi>
</mstyle></math>"""),
'snuggletex_2x+3y.xml'),
('x+x+3y', textwrap.dedent("""
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mi>x</mi><mo>+</mo><mi>x</mi><mo>+</mo><mn>3</mn><mo>*</mo><mi>y</mi>
</mstyle></math>"""),
'snuggletex_x+x+3y.xml'),
]
for (input_str, input_mathml, server_fixture) in correct_inputs:
print "Testing input: {0}".format(input_str)
server_resp = load_fixture(server_fixture)
self._assert_symbolic_grade(
problem, input_str, input_mathml,
'correct', snuggletex_resp=server_resp
)
def test_grade_single_input_incorrect(self): def test_grade_single_input_incorrect(self):
problem = self.build_problem(math_display=True, expect="2*x+3*y") problem = self.build_problem(math_display=True, expect="2*x+3*y")
...@@ -352,23 +324,6 @@ class SymbolicResponseTest(ResponseTest): # pylint: disable=missing-docstring ...@@ -352,23 +324,6 @@ class SymbolicResponseTest(ResponseTest): # pylint: disable=missing-docstring
for (input_str, input_mathml) in incorrect_inputs: for (input_str, input_mathml) in incorrect_inputs:
self._assert_symbolic_grade(problem, input_str, input_mathml, 'incorrect') self._assert_symbolic_grade(problem, input_str, input_mathml, 'incorrect')
def test_complex_number_grade_correct(self):
problem = self.build_problem(
math_display=True,
expect="[[cos(theta),i*sin(theta)],[i*sin(theta),cos(theta)]]",
options=["matrix", "imaginary"]
)
correct_snuggletex = load_fixture('snuggletex_correct.html')
dynamath_input = load_fixture('dynamath_input.txt')
student_response = "cos(theta)*[[1,0],[0,1]] + i*sin(theta)*[[0,1],[1,0]]"
self._assert_symbolic_grade(
problem, student_response, dynamath_input,
'correct',
snuggletex_resp=correct_snuggletex
)
def test_complex_number_grade_incorrect(self): def test_complex_number_grade_incorrect(self):
problem = self.build_problem(math_display=True, problem = self.build_problem(math_display=True,
......
...@@ -2,7 +2,7 @@ from setuptools import setup ...@@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name="symmath", name="symmath",
version="0.1", version="0.2",
packages=["symmath"], packages=["symmath"],
install_requires=[ install_requires=[
"sympy==0.7.1", "sympy==0.7.1",
......
...@@ -21,7 +21,6 @@ import unicodedata ...@@ -21,7 +21,6 @@ import unicodedata
from copy import deepcopy from copy import deepcopy
from xml.sax.saxutils import unescape from xml.sax.saxutils import unescape
import requests
import sympy import sympy
from lxml import etree from lxml import etree
from sympy import latex, sympify from sympy import latex, sympify
...@@ -428,10 +427,7 @@ class formula(object): ...@@ -428,10 +427,7 @@ class formula(object):
return "<html>Error! Cannot process pmathml</html>" return "<html>Error! Cannot process pmathml</html>"
pmathml = etree.tostring(xml, pretty_print=True) pmathml = etree.tostring(xml, pretty_print=True)
self.the_pmathml = pmathml # pylint: disable=attribute-defined-outside-init self.the_pmathml = pmathml # pylint: disable=attribute-defined-outside-init
return self.the_pmathml
# convert to cmathml
self.the_cmathml = self.GetContentMathML(self.asciimath, pmathml)
return self.the_cmathml
cmathml = property(get_content_mathml, None, None, 'content MathML representation') cmathml = property(get_content_mathml, None, None, 'content MathML representation')
...@@ -586,35 +582,3 @@ class formula(object): ...@@ -586,35 +582,3 @@ class formula(object):
raise Exception('[formula] unknown tag %s' % tag) raise Exception('[formula] unknown tag %s' % tag)
sympy = property(make_sympy, None, None, 'sympy representation') sympy = property(make_sympy, None, None, 'sympy representation')
def GetContentMathML(self, asciimath, mathml): # pylint: disable=invalid-name
"""
Handle requests to snuggletex API to convert the Ascii math to MathML
"""
url = 'https://math-xserver.mitx.mit.edu/snuggletex-webapp-1.2.2/ASCIIMathMLUpConversionDemo'
payload = {
'asciiMathInput': asciimath,
'asciiMathML': mathml,
}
headers = {
'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"
}
request = requests.post(url, data=payload, headers=headers, verify=False)
request.encoding = 'utf-8'
ret = request.text
mode = 0
cmathml = []
for k in ret.split('\n'):
if 'conversion to Content MathML' in k:
mode = 1
continue
if mode == 1:
if '<h3>Maxima Input Form</h3>' in k:
mode = 0
continue
cmathml.append(k)
cmathml = '\n'.join(cmathml[2:])
cmathml = '<math xmlns="http://www.w3.org/1998/Math/MathML">\n' + unescape(cmathml) + '\n</math>'
return cmathml
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