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
dba1e4dd
Commit
dba1e4dd
authored
Jan 27, 2014
by
Adam
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2300 from edx/adam/fix/stringresponse-no-type-specified
Adam/fix/stringresponse no type specified
parents
babd2e22
c305fc38
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
19 deletions
+43
-19
common/lib/capa/capa/responsetypes.py
+5
-2
common/lib/capa/capa/tests/response_xml_factory.py
+6
-3
common/lib/capa/capa/tests/test_responsetypes.py
+32
-14
No files found.
common/lib/capa/capa/responsetypes.py
View file @
dba1e4dd
...
...
@@ -1054,8 +1054,11 @@ class StringResponse(LoncapaResponse):
def
setup_response
(
self
):
self
.
backward
=
'_or_'
in
self
.
xml
.
get
(
'answer'
)
.
lower
()
self
.
regexp
=
'regexp'
in
self
.
xml
.
get
(
'type'
)
.
lower
()
.
split
(
' '
)
self
.
case_insensitive
=
'ci'
in
self
.
xml
.
get
(
'type'
)
.
lower
()
.
split
(
' '
)
self
.
regexp
=
False
self
.
case_insensitive
=
False
if
self
.
xml
.
get
(
'type'
)
is
not
None
:
self
.
regexp
=
'regexp'
in
self
.
xml
.
get
(
'type'
)
.
lower
()
.
split
(
' '
)
self
.
case_insensitive
=
'ci'
in
self
.
xml
.
get
(
'type'
)
.
lower
()
.
split
(
' '
)
# backward compatibility, can be removed in future, it is up to @Lyla Fisher.
if
self
.
backward
:
...
...
common/lib/capa/capa/tests/response_xml_factory.py
View file @
dba1e4dd
...
...
@@ -700,7 +700,7 @@ class StringResponseXMLFactory(ResponseXMLFactory):
"""
# Retrieve the **kwargs
answer
=
kwargs
.
get
(
"answer"
,
None
)
case_sensitive
=
kwargs
.
get
(
"case_sensitive"
,
Tru
e
)
case_sensitive
=
kwargs
.
get
(
"case_sensitive"
,
Non
e
)
hint_list
=
kwargs
.
get
(
'hints'
,
None
)
hint_fn
=
kwargs
.
get
(
'hintfn'
,
None
)
regexp
=
kwargs
.
get
(
'regexp'
,
None
)
...
...
@@ -714,9 +714,12 @@ class StringResponseXMLFactory(ResponseXMLFactory):
response_element
.
set
(
"answer"
,
unicode
(
answer
))
# Set the case sensitivity and regexp:
type_value
=
"cs"
if
case_sensitive
else
"ci"
type_value
=
''
if
case_sensitive
is
not
None
:
type_value
+=
"cs"
if
case_sensitive
else
"ci"
type_value
+=
' regexp'
if
regexp
else
''
response_element
.
set
(
"type"
,
type_value
)
if
type_value
:
response_element
.
set
(
"type"
,
type_value
.
strip
())
# Add the hints if specified
if
hint_list
or
hint_fn
:
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
dba1e4dd
...
...
@@ -564,6 +564,10 @@ class StringResponseTest(ResponseTest):
problem
=
self
.
build_problem
(
answer
=
".*tre+"
,
case_sensitive
=
False
,
regexp
=
True
)
self
.
assert_grade
(
problem
,
"There is a tree"
,
"correct"
)
# test with case_sensitive not specified
problem
=
self
.
build_problem
(
answer
=
".*tre+"
,
regexp
=
True
)
self
.
assert_grade
(
problem
,
"There is a tree"
,
"correct"
)
answers
=
[
"Martin Luther King Junior"
,
"Doctor Martin Luther King Junior"
,
...
...
@@ -611,6 +615,7 @@ class StringResponseTest(ResponseTest):
self
.
assert_grade
(
problem
,
u"î"
,
"incorrect"
)
self
.
assert_grade
(
problem
,
u"o"
,
"incorrect"
)
def
test_backslash_and_unicode_regexps
(
self
):
"""
Test some special cases of [unicode] regexps.
...
...
@@ -643,26 +648,39 @@ class StringResponseTest(ResponseTest):
def
test_case_sensitive
(
self
):
# Test single answer
problem
=
self
.
build_problem
(
answer
=
"Second"
,
case_sensitive
=
True
)
problem_specified
=
self
.
build_problem
(
answer
=
"Second"
,
case_sensitive
=
True
)
# should also be case_sensitive if case sensitivity is not specified
problem_not_specified
=
self
.
build_problem
(
answer
=
"Second"
)
problems
=
[
problem_specified
,
problem_not_specified
]
# Exact string should be correct
self
.
assert_grade
(
problem
,
"Second"
,
"correct"
)
for
problem
in
problems
:
# Exact string should be correct
self
.
assert_grade
(
problem
,
"Second"
,
"correct"
)
# Other strings and the lowercase version of the string are incorrect
self
.
assert_grade
(
problem
,
"Other String"
,
"incorrect"
)
self
.
assert_grade
(
problem
,
"second"
,
"incorrect"
)
# Other strings and the lowercase version of the string are incorrect
self
.
assert_grade
(
problem
,
"Other String"
,
"incorrect"
)
self
.
assert_grade
(
problem
,
"second"
,
"incorrect"
)
# Test multiple answers
answers
=
[
"Second"
,
"Third"
,
"Fourth"
]
problem
=
self
.
build_problem
(
answer
=
"sample_answer"
,
case_sensitive
=
True
,
additional_answers
=
answers
)
for
answer
in
answers
:
# Exact string should be correct
self
.
assert_grade
(
problem
,
answer
,
"correct"
)
# Other strings and the lowercase version of the string are incorrect
self
.
assert_grade
(
problem
,
"Other String"
,
"incorrect"
)
self
.
assert_grade
(
problem
,
"second"
,
"incorrect"
)
# set up problems
problem_specified
=
self
.
build_problem
(
answer
=
"sample_answer"
,
case_sensitive
=
True
,
additional_answers
=
answers
)
problem_not_specified
=
self
.
build_problem
(
answer
=
"sample_answer"
,
additional_answers
=
answers
)
problems
=
[
problem_specified
,
problem_not_specified
]
for
problem
in
problems
:
for
answer
in
answers
:
# Exact string should be correct
self
.
assert_grade
(
problem
,
answer
,
"correct"
)
# Other strings and the lowercase version of the string are incorrect
self
.
assert_grade
(
problem
,
"Other String"
,
"incorrect"
)
self
.
assert_grade
(
problem
,
"second"
,
"incorrect"
)
def
test_bogus_escape_not_raised
(
self
):
"""
...
...
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