Skip to content

Commit

Permalink
Ed-1879 Remove requests import in symmath
Browse files Browse the repository at this point in the history
  • Loading branch information
ssemenova committed Dec 12, 2017
1 parent 25eb318 commit 8030f82
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 83 deletions.
45 changes: 0 additions & 45 deletions common/lib/capa/capa/tests/test_responsetypes.py
Expand Up @@ -308,34 +308,6 @@ def test_show_answer(self):
class SymbolicResponseTest(ResponseTest): # pylint: disable=missing-docstring
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):
problem = self.build_problem(math_display=True, expect="2*x+3*y")

Expand All @@ -352,23 +324,6 @@ def test_grade_single_input_incorrect(self):
for (input_str, input_mathml) in incorrect_inputs:
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):

problem = self.build_problem(math_display=True,
Expand Down
2 changes: 1 addition & 1 deletion common/lib/symmath/setup.py
Expand Up @@ -2,7 +2,7 @@

setup(
name="symmath",
version="0.1",
version="0.2",
packages=["symmath"],
install_requires=[
"sympy==0.7.1",
Expand Down
38 changes: 1 addition & 37 deletions common/lib/symmath/symmath/formula.py
Expand Up @@ -21,7 +21,6 @@
from copy import deepcopy
from xml.sax.saxutils import unescape

import requests
import sympy
from lxml import etree
from sympy import latex, sympify
Expand Down Expand Up @@ -428,10 +427,7 @@ def get_content_mathml(self):
return "<html>Error! Cannot process pmathml</html>"
pmathml = etree.tostring(xml, pretty_print=True)
self.the_pmathml = pmathml # pylint: disable=attribute-defined-outside-init

# convert to cmathml
self.the_cmathml = self.GetContentMathML(self.asciimath, pmathml)
return self.the_cmathml
return self.the_pmathml

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

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

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

0 comments on commit 8030f82

Please sign in to comment.