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
06a54a8c
Commit
06a54a8c
authored
Apr 11, 2013
by
Diana Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate tests into one larger test
parent
ab7a6165
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
69 deletions
+24
-69
common/lib/capa/capa/inputtypes.py
+10
-6
common/lib/capa/capa/tests/test_inputtypes.py
+14
-63
No files found.
common/lib/capa/capa/inputtypes.py
View file @
06a54a8c
...
...
@@ -457,17 +457,21 @@ class TextLine(InputTypeBase):
"""
A text line input. Can do math preview if "math"="1" is specified.
If "trailing_text" is set to a value, then the textline will be shown with the value after the text input,
and before the checkmark or any input-specific feedback. HTML will not work, but properly escaped HTML characters will.
This feature is useful if you would like to specify a specific type of units for the text input.
If "trailing_text" is set to a value, then the textline will be shown with
the value after the text input, and before the checkmark or any input-specific
feedback. HTML will not work, but properly escaped HTML characters will. This
feature is useful if you would like to specify a specific type of units for the
text input.
If the hidden attribute is specified, the textline is hidden and the input id is stored in a div with name equal
to the value of the hidden attribute. This is used e.g. for embedding simulations turned into questions.
If the hidden attribute is specified, the textline is hidden and the input id
is stored in a div with name equal to the value of the hidden attribute. This
is used e.g. for embedding simulations turned into questions.
Example:
<texline math="1" trailing_text="m/s" />
This example will render out a text line with a math preview and the text 'm/s' after the end of the text line.
This example will render out a text line with a math preview and the text 'm/s'
after the end of the text line.
"""
template
=
"textline.html"
...
...
common/lib/capa/capa/tests/test_inputtypes.py
View file @
06a54a8c
# coding='utf-8'
"""
feature
Tests of input types.
Tests of input types.
TODO:
- refactor: so much repetive code (have factory methods that build xml elements directly, etc)
...
...
@@ -21,7 +20,6 @@ import json
from
lxml
import
etree
import
unittest
import
xml.sax.saxutils
as
saxutils
import
unicodedata
as
ud
from
.
import
test_system
from
capa
import
inputtypes
...
...
@@ -220,68 +218,21 @@ class TextLineTest(unittest.TestCase):
def
test_trailing_text_rendering
(
self
):
size
=
"42"
trailing_text
=
'm/s'
xml_str
=
"""<textline id="prob_1_2"
size="{size}"
trailing_text="{tt}"
/>"""
.
format
(
size
=
size
,
tt
=
trailing_text
)
element
=
etree
.
fromstring
(
xml_str
)
state
=
{
'value'
:
'BumbleBee'
,
}
the_input
=
lookup_tag
(
'textline'
)(
test_system
,
element
,
state
)
context
=
the_input
.
_get_render_context
()
expected
=
{
'id'
:
'prob_1_2'
,
'value'
:
'BumbleBee'
,
'status'
:
'unanswered'
,
'size'
:
size
,
'msg'
:
''
,
'hidden'
:
False
,
'inline'
:
False
,
'do_math'
:
False
,
'trailing_text'
:
trailing_text
,
'preprocessor'
:
None
}
self
.
assertEqual
(
context
,
expected
)
def
test_trailing_unicode
(
self
):
size
=
"42"
trailing_text
=
u'
\xc3
'
print
trailing_text
# store (xml_text, expected)
trailing_text
=
[]
# standard trailing text
trailing_text
.
append
((
'm/s'
,
'm/s'
))
# unicode trailing text
trailing_text
.
append
((
u'
\xc3
'
,
u'
\xc3
'
))
# html escaped trailing text
# this is the only one we expect to change
trailing_text
.
append
((
'a < b'
,
'a < b'
))
for
xml_text
,
expected_text
in
trailing_text
:
xml_str
=
u"""<textline id="prob_1_2"
size="{size}"
trailing_text="{tt}"
/>"""
.
format
(
size
=
size
,
tt
=
trailing_text
)
element
=
etree
.
fromstring
(
xml_str
)
state
=
{
'value'
:
'BumbleBee'
,
}
the_input
=
lookup_tag
(
'textline'
)(
test_system
,
element
,
state
)
context
=
the_input
.
_get_render_context
()
expected
=
{
'id'
:
'prob_1_2'
,
'value'
:
'BumbleBee'
,
'status'
:
'unanswered'
,
'size'
:
size
,
'msg'
:
''
,
'hidden'
:
False
,
'inline'
:
False
,
'do_math'
:
False
,
'trailing_text'
:
trailing_text
,
'preprocessor'
:
None
}
self
.
assertEqual
(
context
,
expected
)
def
test_trailing_text_special_characters
(
self
):
size
=
"42"
trailing_text
=
'a < b'
xml_str
=
"""<textline id="prob_1_2"
size="{size}"
trailing_text="{tt}"
/>"""
.
format
(
size
=
size
,
tt
=
trailing_text
)
/>"""
.
format
(
size
=
size
,
tt
=
xml_text
)
element
=
etree
.
fromstring
(
xml_str
)
...
...
@@ -298,7 +249,7 @@ class TextLineTest(unittest.TestCase):
'hidden'
:
False
,
'inline'
:
False
,
'do_math'
:
False
,
'trailing_text'
:
'a < b'
,
'trailing_text'
:
expected_text
,
'preprocessor'
:
None
}
self
.
assertEqual
(
context
,
expected
)
...
...
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