Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
8030f82e
Commit
8030f82e
authored
Dec 11, 2017
by
Sofiya Semenova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ed-1879 Remove requests import in symmath
parent
25eb3187
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2 additions
and
83 deletions
+2
-83
common/lib/capa/capa/tests/test_responsetypes.py
+0
-45
common/lib/symmath/setup.py
+1
-1
common/lib/symmath/symmath/formula.py
+1
-37
No files found.
common/lib/capa/capa/tests/test_responsetypes.py
View file @
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
,
...
...
common/lib/symmath/setup.py
View file @
8030f82e
...
@@ -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"
,
...
...
common/lib/symmath/symmath/formula.py
View file @
8030f82e
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment