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
53cf8aa7
Commit
53cf8aa7
authored
Apr 01, 2013
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1789 from MITx/fix/will/chem_customresponse_bug
Fix/will/chem customresponse bug
parents
ec06b366
1cba122d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
+65
-0
common/lib/capa/capa/capa_problem.py
+5
-0
common/lib/capa/capa/tests/test_responsetypes.py
+60
-0
No files found.
common/lib/capa/capa/capa_problem.py
View file @
53cf8aa7
...
...
@@ -32,6 +32,8 @@ from copy import deepcopy
import
chem
import
chem.miller
import
chem.chemcalc
import
chem.chemtools
import
verifiers
import
verifiers.draganddrop
...
...
@@ -67,6 +69,9 @@ global_context = {'random': random,
'scipy'
:
scipy
,
'calc'
:
calc
,
'eia'
:
eia
,
'chemcalc'
:
chem
.
chemcalc
,
'chemtools'
:
chem
.
chemtools
,
'miller'
:
chem
.
miller
,
'draganddrop'
:
verifiers
.
draganddrop
}
# These should be removed from HTML output, including all subelements
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
53cf8aa7
...
...
@@ -905,6 +905,66 @@ class CustomResponseTest(ResponseTest):
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
def
test_module_imports_inline
(
self
):
'''
Check that the correct modules are available to custom
response scripts
'''
for
module_name
in
[
'random'
,
'numpy'
,
'math'
,
'scipy'
,
'calc'
,
'eia'
,
'chemcalc'
,
'chemtools'
,
'miller'
,
'draganddrop'
]:
# Create a script that checks that the name is defined
# If the name is not defined, then the script
# will raise an exception
script
=
textwrap
.
dedent
(
'''
correct[0] = 'correct'
assert('
%
s' in globals())'''
%
module_name
)
# Create the problem
problem
=
self
.
build_problem
(
answer
=
script
)
# Expect that we can grade an answer without
# getting an exception
try
:
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
except
ResponseError
:
self
.
fail
(
"Could not use name '
%
s' in custom response"
%
module_name
)
def
test_module_imports_function
(
self
):
'''
Check that the correct modules are available to custom
response scripts
'''
for
module_name
in
[
'random'
,
'numpy'
,
'math'
,
'scipy'
,
'calc'
,
'eia'
,
'chemcalc'
,
'chemtools'
,
'miller'
,
'draganddrop'
]:
# Create a script that checks that the name is defined
# If the name is not defined, then the script
# will raise an exception
script
=
textwrap
.
dedent
(
'''
def check_func(expect, answer_given):
assert('
%
s' in globals())
return True'''
%
module_name
)
# Create the problem
problem
=
self
.
build_problem
(
script
=
script
,
cfn
=
"check_func"
)
# Expect that we can grade an answer without
# getting an exception
try
:
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
except
ResponseError
:
self
.
fail
(
"Could not use name '
%
s' in custom response"
%
module_name
)
class
SchematicResponseTest
(
ResponseTest
):
from
response_xml_factory
import
SchematicResponseXMLFactory
xml_factory_class
=
SchematicResponseXMLFactory
...
...
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