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
d4536c65
Commit
d4536c65
authored
Apr 12, 2013
by
Diana Huang
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1852 from MITx/feature/diana/textline-trailing
Pylint and Pep8 fixes for InputTypes
parents
13aed417
ff1189c5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
39 deletions
+24
-39
common/lib/capa/capa/inputtypes.py
+10
-13
common/lib/capa/capa/tests/test_inputtypes.py
+14
-26
No files found.
common/lib/capa/capa/inputtypes.py
View file @
d4536c65
...
@@ -150,8 +150,8 @@ class InputTypeBase(object):
...
@@ -150,8 +150,8 @@ class InputTypeBase(object):
## we can swap this around in the future if there's a more logical
## we can swap this around in the future if there's a more logical
## order.
## order.
self
.
id
=
state
.
get
(
'id'
,
xml
.
get
(
'id'
))
self
.
i
nput_i
d
=
state
.
get
(
'id'
,
xml
.
get
(
'id'
))
if
self
.
id
is
None
:
if
self
.
i
nput_i
d
is
None
:
raise
ValueError
(
"input id state is None. xml is {0}"
.
format
(
raise
ValueError
(
"input id state is None. xml is {0}"
.
format
(
etree
.
tostring
(
xml
)))
etree
.
tostring
(
xml
)))
...
@@ -249,7 +249,7 @@ class InputTypeBase(object):
...
@@ -249,7 +249,7 @@ class InputTypeBase(object):
and don't need to override this method.
and don't need to override this method.
"""
"""
context
=
{
context
=
{
'id'
:
self
.
id
,
'id'
:
self
.
i
nput_i
d
,
'value'
:
self
.
value
,
'value'
:
self
.
value
,
'status'
:
self
.
status
,
'status'
:
self
.
status
,
'msg'
:
self
.
msg
,
'msg'
:
self
.
msg
,
...
@@ -623,7 +623,6 @@ class CodeInput(InputTypeBase):
...
@@ -623,7 +623,6 @@ class CodeInput(InputTypeBase):
self
.
queue_len
=
self
.
msg
self
.
queue_len
=
self
.
msg
self
.
msg
=
self
.
submitted_msg
self
.
msg
=
self
.
submitted_msg
def
setup
(
self
):
def
setup
(
self
):
''' setup this input type '''
''' setup this input type '''
self
.
setup_code_response_rendering
()
self
.
setup_code_response_rendering
()
...
@@ -676,7 +675,6 @@ class MatlabInput(CodeInput):
...
@@ -676,7 +675,6 @@ class MatlabInput(CodeInput):
self
.
queue_len
=
1
self
.
queue_len
=
1
self
.
msg
=
self
.
plot_submitted_msg
self
.
msg
=
self
.
plot_submitted_msg
def
handle_ajax
(
self
,
dispatch
,
get
):
def
handle_ajax
(
self
,
dispatch
,
get
):
'''
'''
Handle AJAX calls directed to this input
Handle AJAX calls directed to this input
...
@@ -685,7 +683,8 @@ class MatlabInput(CodeInput):
...
@@ -685,7 +683,8 @@ class MatlabInput(CodeInput):
- dispatch (str) - indicates how we want this ajax call to be handled
- dispatch (str) - indicates how we want this ajax call to be handled
- get (dict) - dictionary of key-value pairs that contain useful data
- get (dict) - dictionary of key-value pairs that contain useful data
Returns:
Returns:
dict - 'success' - whether or not we successfully queued this submission
- 'message' - message to be rendered in case of error
'''
'''
if
dispatch
==
'plot'
:
if
dispatch
==
'plot'
:
...
@@ -738,7 +737,6 @@ class MatlabInput(CodeInput):
...
@@ -738,7 +737,6 @@ class MatlabInput(CodeInput):
msg
=
result
[
'msg'
]
msg
=
result
[
'msg'
]
return
msg
return
msg
def
_plot_data
(
self
,
get
):
def
_plot_data
(
self
,
get
):
'''
'''
AJAX handler for the plot button
AJAX handler for the plot button
...
@@ -762,17 +760,16 @@ class MatlabInput(CodeInput):
...
@@ -762,17 +760,16 @@ class MatlabInput(CodeInput):
anonymous_student_id
=
self
.
system
.
anonymous_student_id
anonymous_student_id
=
self
.
system
.
anonymous_student_id
queuekey
=
xqueue_interface
.
make_hashkey
(
str
(
self
.
system
.
seed
)
+
qtime
+
queuekey
=
xqueue_interface
.
make_hashkey
(
str
(
self
.
system
.
seed
)
+
qtime
+
anonymous_student_id
+
anonymous_student_id
+
self
.
id
)
self
.
i
nput_i
d
)
xheader
=
xqueue_interface
.
make_xheader
(
xheader
=
xqueue_interface
.
make_xheader
(
lms_callback_url
=
callback_url
,
lms_callback_url
=
callback_url
,
lms_key
=
queuekey
,
lms_key
=
queuekey
,
queue_name
=
self
.
queuename
)
queue_name
=
self
.
queuename
)
# save the input state
# save the input state
self
.
input_state
[
'queuekey'
]
=
queuekey
self
.
input_state
[
'queuekey'
]
=
queuekey
self
.
input_state
[
'queuestate'
]
=
'queued'
self
.
input_state
[
'queuestate'
]
=
'queued'
# construct xqueue body
# construct xqueue body
student_info
=
{
'anonymous_student_id'
:
anonymous_student_id
,
student_info
=
{
'anonymous_student_id'
:
anonymous_student_id
,
'submission_time'
:
qtime
}
'submission_time'
:
qtime
}
...
@@ -781,7 +778,7 @@ class MatlabInput(CodeInput):
...
@@ -781,7 +778,7 @@ class MatlabInput(CodeInput):
'student_response'
:
response
}
'student_response'
:
response
}
(
error
,
msg
)
=
qinterface
.
send_to_queue
(
header
=
xheader
,
(
error
,
msg
)
=
qinterface
.
send_to_queue
(
header
=
xheader
,
body
=
json
.
dumps
(
contents
))
body
=
json
.
dumps
(
contents
))
return
{
'success'
:
error
==
0
,
'message'
:
msg
}
return
{
'success'
:
error
==
0
,
'message'
:
msg
}
...
...
common/lib/capa/capa/tests/test_inputtypes.py
View file @
d4536c65
...
@@ -60,6 +60,7 @@ class OptionInputTest(unittest.TestCase):
...
@@ -60,6 +60,7 @@ class OptionInputTest(unittest.TestCase):
def
test_option_parsing
(
self
):
def
test_option_parsing
(
self
):
f
=
inputtypes
.
OptionInput
.
parse_options
f
=
inputtypes
.
OptionInput
.
parse_options
def
check
(
input
,
options
):
def
check
(
input
,
options
):
"""Take list of options, confirm that output is in the silly doubled format"""
"""Take list of options, confirm that output is in the silly doubled format"""
expected
=
[(
o
,
o
)
for
o
in
options
]
expected
=
[(
o
,
o
)
for
o
in
options
]
...
@@ -120,7 +121,6 @@ class ChoiceGroupTest(unittest.TestCase):
...
@@ -120,7 +121,6 @@ class ChoiceGroupTest(unittest.TestCase):
self
.
check_group
(
'checkboxgroup'
,
'checkbox'
,
'[]'
)
self
.
check_group
(
'checkboxgroup'
,
'checkbox'
,
'[]'
)
class
JavascriptInputTest
(
unittest
.
TestCase
):
class
JavascriptInputTest
(
unittest
.
TestCase
):
'''
'''
The javascript input is a pretty straightforward pass-thru, but test it anyway
The javascript input is a pretty straightforward pass-thru, but test it anyway
...
@@ -186,7 +186,6 @@ class TextLineTest(unittest.TestCase):
...
@@ -186,7 +186,6 @@ class TextLineTest(unittest.TestCase):
'preprocessor'
:
None
}
'preprocessor'
:
None
}
self
.
assertEqual
(
context
,
expected
)
self
.
assertEqual
(
context
,
expected
)
def
test_math_rendering
(
self
):
def
test_math_rendering
(
self
):
size
=
"42"
size
=
"42"
preprocessorClass
=
"preParty"
preprocessorClass
=
"preParty"
...
@@ -226,7 +225,7 @@ class TextLineTest(unittest.TestCase):
...
@@ -226,7 +225,7 @@ class TextLineTest(unittest.TestCase):
trailing_text
.
append
((
u'
\xc3
'
,
u'
\xc3
'
))
trailing_text
.
append
((
u'
\xc3
'
,
u'
\xc3
'
))
# html escaped trailing text
# html escaped trailing text
# this is the only one we expect to change
# this is the only one we expect to change
trailing_text
.
append
((
'a < b'
,
'a < b'
))
trailing_text
.
append
((
'a < b'
,
'a < b'
))
for
xml_text
,
expected_text
in
trailing_text
:
for
xml_text
,
expected_text
in
trailing_text
:
xml_str
=
u"""<textline id="prob_1_2"
xml_str
=
u"""<textline id="prob_1_2"
...
@@ -269,7 +268,6 @@ class FileSubmissionTest(unittest.TestCase):
...
@@ -269,7 +268,6 @@ class FileSubmissionTest(unittest.TestCase):
/>"""
.
format
(
af
=
allowed_files
,
/>"""
.
format
(
af
=
allowed_files
,
rf
=
required_files
,)
rf
=
required_files
,)
element
=
etree
.
fromstring
(
xml_str
)
element
=
etree
.
fromstring
(
xml_str
)
state
=
{
'value'
:
'BumbleBee.py'
,
state
=
{
'value'
:
'BumbleBee.py'
,
...
@@ -335,11 +333,11 @@ class CodeInputTest(unittest.TestCase):
...
@@ -335,11 +333,11 @@ class CodeInputTest(unittest.TestCase):
'cols'
:
cols
,
'cols'
:
cols
,
'hidden'
:
''
,
'hidden'
:
''
,
'tabsize'
:
int
(
tabsize
),
'tabsize'
:
int
(
tabsize
),
'queue_len'
:
'3'
,
'queue_len'
:
'3'
}
}
self
.
assertEqual
(
context
,
expected
)
self
.
assertEqual
(
context
,
expected
)
class
MatlabTest
(
unittest
.
TestCase
):
class
MatlabTest
(
unittest
.
TestCase
):
'''
'''
Test Matlab input types
Test Matlab input types
...
@@ -358,12 +356,12 @@ class MatlabTest(unittest.TestCase):
...
@@ -358,12 +356,12 @@ class MatlabTest(unittest.TestCase):
<plot_payload>
<plot_payload>
{payload}
{payload}
</plot_payload>
</plot_payload>
</matlabinput>"""
.
format
(
r
=
self
.
rows
,
</matlabinput>"""
.
format
(
r
=
self
.
rows
,
c
=
self
.
cols
,
c
=
self
.
cols
,
tabsize
=
self
.
tabsize
,
tabsize
=
self
.
tabsize
,
m
=
self
.
mode
,
m
=
self
.
mode
,
payload
=
self
.
payload
,
payload
=
self
.
payload
,
ln
=
self
.
linenumbers
)
ln
=
self
.
linenumbers
)
elt
=
etree
.
fromstring
(
self
.
xml
)
elt
=
etree
.
fromstring
(
self
.
xml
)
state
=
{
'value'
:
'print "good evening"'
,
state
=
{
'value'
:
'print "good evening"'
,
'status'
:
'incomplete'
,
'status'
:
'incomplete'
,
...
@@ -372,7 +370,6 @@ class MatlabTest(unittest.TestCase):
...
@@ -372,7 +370,6 @@ class MatlabTest(unittest.TestCase):
self
.
input_class
=
lookup_tag
(
'matlabinput'
)
self
.
input_class
=
lookup_tag
(
'matlabinput'
)
self
.
the_input
=
self
.
input_class
(
test_system
,
elt
,
state
)
self
.
the_input
=
self
.
input_class
(
test_system
,
elt
,
state
)
def
test_rendering
(
self
):
def
test_rendering
(
self
):
context
=
self
.
the_input
.
_get_render_context
()
context
=
self
.
the_input
.
_get_render_context
()
...
@@ -387,12 +384,10 @@ class MatlabTest(unittest.TestCase):
...
@@ -387,12 +384,10 @@ class MatlabTest(unittest.TestCase):
'linenumbers'
:
'true'
,
'linenumbers'
:
'true'
,
'hidden'
:
''
,
'hidden'
:
''
,
'tabsize'
:
int
(
self
.
tabsize
),
'tabsize'
:
int
(
self
.
tabsize
),
'queue_len'
:
'3'
,
'queue_len'
:
'3'
}
}
self
.
assertEqual
(
context
,
expected
)
self
.
assertEqual
(
context
,
expected
)
def
test_rendering_with_state
(
self
):
def
test_rendering_with_state
(
self
):
state
=
{
'value'
:
'print "good evening"'
,
state
=
{
'value'
:
'print "good evening"'
,
'status'
:
'incomplete'
,
'status'
:
'incomplete'
,
...
@@ -414,8 +409,7 @@ class MatlabTest(unittest.TestCase):
...
@@ -414,8 +409,7 @@ class MatlabTest(unittest.TestCase):
'linenumbers'
:
'true'
,
'linenumbers'
:
'true'
,
'hidden'
:
''
,
'hidden'
:
''
,
'tabsize'
:
int
(
self
.
tabsize
),
'tabsize'
:
int
(
self
.
tabsize
),
'queue_len'
:
'3'
,
'queue_len'
:
'3'
}
}
self
.
assertEqual
(
context
,
expected
)
self
.
assertEqual
(
context
,
expected
)
...
@@ -439,8 +433,7 @@ class MatlabTest(unittest.TestCase):
...
@@ -439,8 +433,7 @@ class MatlabTest(unittest.TestCase):
'linenumbers'
:
'true'
,
'linenumbers'
:
'true'
,
'hidden'
:
''
,
'hidden'
:
''
,
'tabsize'
:
int
(
self
.
tabsize
),
'tabsize'
:
int
(
self
.
tabsize
),
'queue_len'
:
'1'
,
'queue_len'
:
'1'
}
}
self
.
assertEqual
(
context
,
expected
)
self
.
assertEqual
(
context
,
expected
)
...
@@ -491,9 +484,6 @@ class MatlabTest(unittest.TestCase):
...
@@ -491,9 +484,6 @@ class MatlabTest(unittest.TestCase):
self
.
assertFalse
(
'queue_msg'
in
input_state
)
self
.
assertFalse
(
'queue_msg'
in
input_state
)
class
SchematicTest
(
unittest
.
TestCase
):
class
SchematicTest
(
unittest
.
TestCase
):
'''
'''
Check that schematic inputs work
Check that schematic inputs work
...
@@ -507,7 +497,6 @@ class SchematicTest(unittest.TestCase):
...
@@ -507,7 +497,6 @@ class SchematicTest(unittest.TestCase):
initial_value
=
'two large batteries'
initial_value
=
'two large batteries'
submit_analyses
=
'maybe'
submit_analyses
=
'maybe'
xml_str
=
"""<schematic id="prob_1_2"
xml_str
=
"""<schematic id="prob_1_2"
height="{h}"
height="{h}"
width="{w}"
width="{w}"
...
@@ -537,8 +526,7 @@ class SchematicTest(unittest.TestCase):
...
@@ -537,8 +526,7 @@ class SchematicTest(unittest.TestCase):
'height'
:
height
,
'height'
:
height
,
'parts'
:
parts
,
'parts'
:
parts
,
'analyses'
:
analyses
,
'analyses'
:
analyses
,
'submit_analyses'
:
submit_analyses
,
'submit_analyses'
:
submit_analyses
}
}
self
.
assertEqual
(
context
,
expected
)
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