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
82651814
Commit
82651814
authored
Mar 01, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If there are multiple inputs, but only one message specified,
the message is now applied to the entire response.
parent
c3da73ed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
42 deletions
+54
-42
common/lib/capa/capa/responsetypes.py
+23
-14
common/lib/capa/capa/tests/test_responsetypes.py
+31
-28
No files found.
common/lib/capa/capa/responsetypes.py
View file @
82651814
...
...
@@ -1086,11 +1086,17 @@ def sympy_check2():
# form {'ok': BOOLEAN, 'msg': STRING}
# If there are multiple inputs, they all get marked
# to the same correct/incorrect value
# and the first input stores the message
if
'ok'
in
ret
:
correct
=
[
'correct'
]
*
len
(
idset
)
if
ret
[
'ok'
]
else
[
'incorrect'
]
*
len
(
idset
)
msg
=
ret
.
get
(
'msg'
,
None
)
messages
[
0
]
=
self
.
clean_message_html
(
msg
)
msg
=
self
.
clean_message_html
(
msg
)
# If there is only one input, apply the message to that input
# Otherwise, apply the message to the whole problem
if
len
(
idset
)
>
1
:
overall_message
=
msg
else
:
messages
[
0
]
=
msg
# Another kind of dictionary the check function can return has
...
...
@@ -1137,18 +1143,21 @@ def sympy_check2():
return
correct_map
def
clean_message_html
(
self
,
msg
):
# try to clean up message html
msg
=
'<html>'
+
msg
+
'</html>'
msg
=
msg
.
replace
(
'<'
,
'<'
)
#msg = msg.replace('<','<')
msg
=
etree
.
tostring
(
fromstring_bs
(
msg
,
convertEntities
=
None
),
pretty_print
=
True
)
#msg = etree.tostring(fromstring_bs(msg),pretty_print=True)
msg
=
msg
.
replace
(
' '
,
''
)
#msg = re.sub('<html>(.*)</html>','\\1',msg,flags=re.M|re.DOTALL) # python 2.7
msg
=
re
.
sub
(
'(?ms)<html>(.*)</html>'
,
'
\\
1'
,
msg
)
return
msg
.
strip
()
if
msg
:
# try to clean up message html
msg
=
'<html>'
+
msg
+
'</html>'
msg
=
msg
.
replace
(
'<'
,
'<'
)
#msg = msg.replace('<','<')
msg
=
etree
.
tostring
(
fromstring_bs
(
msg
,
convertEntities
=
None
),
pretty_print
=
True
)
#msg = etree.tostring(fromstring_bs(msg),pretty_print=True)
msg
=
msg
.
replace
(
' '
,
''
)
#msg = re.sub('<html>(.*)</html>','\\1',msg,flags=re.M|re.DOTALL) # python 2.7
msg
=
re
.
sub
(
'(?ms)<html>(.*)</html>'
,
'
\\
1'
,
msg
)
return
msg
.
strip
()
else
:
return
""
def
get_answers
(
self
):
'''
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
82651814
...
...
@@ -759,34 +759,6 @@ class CustomResponseTest(ResponseTest):
correctness
=
correct_map
.
get_correctness
(
'1_2_2'
)
self
.
assertEqual
(
correctness
,
'incorrect'
)
def
test_script_exception
(
self
):
# Construct a script that will raise an exception
script
=
textwrap
.
dedent
(
"""
def check_func(expect, answer_given):
raise Exception("Test")
"""
)
problem
=
self
.
build_problem
(
script
=
script
,
cfn
=
"check_func"
)
# Expect that an exception gets raised when we check the answer
with
self
.
assertRaises
(
Exception
):
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
def
test_invalid_dict_exception
(
self
):
# Construct a script that passes back an invalid dict format
script
=
textwrap
.
dedent
(
"""
def check_func(expect, answer_given):
return {'invalid': 'test'}
"""
)
problem
=
self
.
build_problem
(
script
=
script
,
cfn
=
"check_func"
)
# Expect that an exception gets raised when we check the answer
with
self
.
assertRaises
(
Exception
):
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
def
test_function_code_multiple_inputs
(
self
):
...
...
@@ -874,6 +846,37 @@ class CustomResponseTest(ResponseTest):
self
.
assertEqual
(
correct_map
.
get_correctness
(
'1_2_2'
),
'correct'
)
self
.
assertEqual
(
correct_map
.
get_correctness
(
'1_2_3'
),
'correct'
)
# Message is interpreted as an "overall message"
self
.
assertEqual
(
correct_map
.
get_overall_message
(),
'Message text'
)
def
test_script_exception
(
self
):
# Construct a script that will raise an exception
script
=
textwrap
.
dedent
(
"""
def check_func(expect, answer_given):
raise Exception("Test")
"""
)
problem
=
self
.
build_problem
(
script
=
script
,
cfn
=
"check_func"
)
# Expect that an exception gets raised when we check the answer
with
self
.
assertRaises
(
Exception
):
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
def
test_invalid_dict_exception
(
self
):
# Construct a script that passes back an invalid dict format
script
=
textwrap
.
dedent
(
"""
def check_func(expect, answer_given):
return {'invalid': 'test'}
"""
)
problem
=
self
.
build_problem
(
script
=
script
,
cfn
=
"check_func"
)
# Expect that an exception gets raised when we check the answer
with
self
.
assertRaises
(
Exception
):
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
class
SchematicResponseTest
(
ResponseTest
):
from
response_xml_factory
import
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