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
f95331dc
Commit
f95331dc
authored
Apr 29, 2013
by
Sarina Canelake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix more pep8 violations
parent
6993daf1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
18 deletions
+11
-18
common/lib/capa/capa/tests/test_responsetypes.py
+11
-18
No files found.
common/lib/capa/capa/tests/test_responsetypes.py
View file @
f95331dc
...
@@ -7,6 +7,7 @@ from datetime import datetime
...
@@ -7,6 +7,7 @@ from datetime import datetime
import
json
import
json
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
os
import
os
import
random
import
unittest
import
unittest
import
textwrap
import
textwrap
...
@@ -360,10 +361,9 @@ class FormulaResponseTest(ResponseTest):
...
@@ -360,10 +361,9 @@ class FormulaResponseTest(ResponseTest):
self
.
assert_grade
(
problem
,
'2*x'
,
'correct'
)
self
.
assert_grade
(
problem
,
'2*x'
,
'correct'
)
self
.
assert_grade
(
problem
,
'3*x'
,
'incorrect'
)
self
.
assert_grade
(
problem
,
'3*x'
,
'incorrect'
)
def
test_parallel_resistors
(
self
):
def
test_parallel_resistors
(
self
):
"""Test parallel resistors"""
"""Test parallel resistors"""
sample_dict
=
{
'R1'
:
(
10
,
10
),
'R2'
:
(
2
,
2
),
'R3'
:
(
5
,
5
),
'R4'
:
(
1
,
1
)}
sample_dict
=
{
'R1'
:
(
10
,
10
),
'R2'
:
(
2
,
2
),
'R3'
:
(
5
,
5
),
'R4'
:
(
1
,
1
)}
# Test problem
# Test problem
problem
=
self
.
build_problem
(
sample_dict
=
sample_dict
,
problem
=
self
.
build_problem
(
sample_dict
=
sample_dict
,
...
@@ -389,8 +389,8 @@ class FormulaResponseTest(ResponseTest):
...
@@ -389,8 +389,8 @@ class FormulaResponseTest(ResponseTest):
# Sample x in the range [-10,10]
# Sample x in the range [-10,10]
sample_dict
=
{
'x'
:
(
-
10
,
10
)}
sample_dict
=
{
'x'
:
(
-
10
,
10
)}
default_variables
=
[(
'j'
,
2
,
3
),
(
'e'
,
2
,
3
),
(
'pi'
,
2
,
3
),
(
'c'
,
2
,
3
),
(
'T'
,
2
,
3
),
default_variables
=
[(
'j'
,
2
,
3
),
(
'e'
,
2
,
3
),
(
'pi'
,
2
,
3
),
(
'c'
,
2
,
3
),
(
'T'
,
2
,
3
),
(
'k'
,
2
*
10
**
23
,
3
*
10
**
23
),
# note k = scipy.constants.k = 1.3806488e-23
(
'k'
,
2
*
10
**
23
,
3
*
10
**
23
),
# note k = scipy.constants.k = 1.3806488e-23
(
'q'
,
2
*
10
**
19
,
3
*
10
**
19
)]
# note k = scipy.constants.e = 1.602176565e-19
(
'q'
,
2
*
10
**
19
,
3
*
10
**
19
)]
# note k = scipy.constants.e = 1.602176565e-19
for
(
var
,
cscalar
,
iscalar
)
in
default_variables
:
for
(
var
,
cscalar
,
iscalar
)
in
default_variables
:
# The expected solution is numerically equivalent to cscalar*var
# The expected solution is numerically equivalent to cscalar*var
correct
=
'{0}*x*{1}'
.
format
(
cscalar
,
var
)
correct
=
'{0}*x*{1}'
.
format
(
cscalar
,
var
)
...
@@ -399,8 +399,8 @@ class FormulaResponseTest(ResponseTest):
...
@@ -399,8 +399,8 @@ class FormulaResponseTest(ResponseTest):
num_samples
=
10
,
num_samples
=
10
,
tolerance
=
0.01
,
tolerance
=
0.01
,
answer
=
correct
)
answer
=
correct
)
# Expect that the inputs are graded correctly
# Expect that the inputs are graded correctly
self
.
assert_grade
(
problem
,
correct
,
'correct'
,
self
.
assert_grade
(
problem
,
correct
,
'correct'
,
msg
=
"Failed on variable {0}; the given, correct answer was {1} but graded 'incorrect'"
.
format
(
var
,
correct
))
msg
=
"Failed on variable {0}; the given, correct answer was {1} but graded 'incorrect'"
.
format
(
var
,
correct
))
self
.
assert_grade
(
problem
,
incorrect
,
'incorrect'
,
self
.
assert_grade
(
problem
,
incorrect
,
'incorrect'
,
...
@@ -412,17 +412,16 @@ class FormulaResponseTest(ResponseTest):
...
@@ -412,17 +412,16 @@ class FormulaResponseTest(ResponseTest):
# arccos, arcsin, arctan, abs,
# arccos, arcsin, arctan, abs,
# fact, factorial
# fact, factorial
import
random
w
=
random
.
randint
(
3
,
10
)
w
=
random
.
randint
(
3
,
10
)
sample_dict
=
{
'x'
:
(
-
10
,
10
),
# Sample x in the range [-10,10]
sample_dict
=
{
'x'
:
(
-
10
,
10
),
# Sample x in the range [-10,10]
'y'
:
(
1
,
10
),
# Sample y in the range [1,10] - logs, arccos need positive inputs
'y'
:
(
1
,
10
),
# Sample y in the range [1,10] - logs, arccos need positive inputs
'z'
:(
-
1
,
1
),
# Sample z in the range [1,10] - for arcsin, arctan
'z'
:
(
-
1
,
1
),
# Sample z in the range [1,10] - for arcsin, arctan
'w'
:
(
w
,
w
)}
# Sample w is a random, positive integer - factorial needs a positive, integer input,
'w'
:
(
w
,
w
)}
# Sample w is a random, positive integer - factorial needs a positive, integer input,
# and the way formularesponse is defined, we can only specify a float range
# and the way formularesponse is defined, we can only specify a float range
default_functions
=
[(
'sin'
,
2
,
3
,
'x'
),
(
'cos'
,
2
,
3
,
'x'
),
(
'tan'
,
2
,
3
,
'x'
),
(
'sqrt'
,
2
,
3
,
'y'
),
(
'log10'
,
2
,
3
,
'y'
),
default_functions
=
[(
'sin'
,
2
,
3
,
'x'
),
(
'cos'
,
2
,
3
,
'x'
),
(
'tan'
,
2
,
3
,
'x'
),
(
'sqrt'
,
2
,
3
,
'y'
),
(
'log10'
,
2
,
3
,
'y'
),
(
'log2'
,
2
,
3
,
'y'
),
(
'ln'
,
2
,
3
,
'y'
),
(
'arccos'
,
2
,
3
,
'z'
),
(
'arcsin'
,
2
,
3
,
'z'
),
(
'arctan'
,
2
,
3
,
'x'
),
(
'log2'
,
2
,
3
,
'y'
),
(
'ln'
,
2
,
3
,
'y'
),
(
'arccos'
,
2
,
3
,
'z'
),
(
'arcsin'
,
2
,
3
,
'z'
),
(
'arctan'
,
2
,
3
,
'x'
),
(
'abs'
,
2
,
3
,
'x'
),
(
'fact'
,
2
,
3
,
'w'
),
(
'factorial'
,
2
,
3
,
'w'
)
,
]
(
'abs'
,
2
,
3
,
'x'
),
(
'fact'
,
2
,
3
,
'w'
),
(
'factorial'
,
2
,
3
,
'w'
)]
for
(
func
,
cscalar
,
iscalar
,
var
)
in
default_functions
:
for
(
func
,
cscalar
,
iscalar
,
var
)
in
default_functions
:
print
'func is: {0}'
.
format
(
func
)
print
'func is: {0}'
.
format
(
func
)
# The expected solution is numerically equivalent to cscalar*func(var)
# The expected solution is numerically equivalent to cscalar*func(var)
...
@@ -432,17 +431,14 @@ class FormulaResponseTest(ResponseTest):
...
@@ -432,17 +431,14 @@ class FormulaResponseTest(ResponseTest):
num_samples
=
10
,
num_samples
=
10
,
tolerance
=
0.01
,
tolerance
=
0.01
,
answer
=
correct
)
answer
=
correct
)
# Expect that the inputs are graded correctly
# Expect that the inputs are graded correctly
self
.
assert_grade
(
problem
,
correct
,
'correct'
,
self
.
assert_grade
(
problem
,
correct
,
'correct'
,
msg
=
"Failed on function {0}; the given, correct answer was {1} but graded 'incorrect'"
.
format
(
func
,
correct
))
msg
=
"Failed on function {0}; the given, correct answer was {1} but graded 'incorrect'"
.
format
(
func
,
correct
))
self
.
assert_grade
(
problem
,
incorrect
,
'incorrect'
,
self
.
assert_grade
(
problem
,
incorrect
,
'incorrect'
,
msg
=
"Failed on function {0}; the given, incorrect answer was {1} but graded 'correct'"
.
format
(
func
,
incorrect
))
msg
=
"Failed on function {0}; the given, incorrect answer was {1} but graded 'correct'"
.
format
(
func
,
incorrect
))
class
StringResponseTest
(
ResponseTest
):
class
StringResponseTest
(
ResponseTest
):
from
response_xml_factory
import
StringResponseXMLFactory
from
response_xml_factory
import
StringResponseXMLFactory
xml_factory_class
=
StringResponseXMLFactory
xml_factory_class
=
StringResponseXMLFactory
...
@@ -989,7 +985,6 @@ class CustomResponseTest(ResponseTest):
...
@@ -989,7 +985,6 @@ class CustomResponseTest(ResponseTest):
with
self
.
assertRaises
(
ResponseError
):
with
self
.
assertRaises
(
ResponseError
):
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
def
test_module_imports_inline
(
self
):
def
test_module_imports_inline
(
self
):
'''
'''
Check that the correct modules are available to custom
Check that the correct modules are available to custom
...
@@ -1016,8 +1011,7 @@ class CustomResponseTest(ResponseTest):
...
@@ -1016,8 +1011,7 @@ class CustomResponseTest(ResponseTest):
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
except
ResponseError
:
except
ResponseError
:
self
.
fail
(
"Could not use name '
%
s' in custom response"
self
.
fail
(
"Could not use name '{0}s' in custom response"
.
format
(
module_name
))
%
module_name
)
def
test_module_imports_function
(
self
):
def
test_module_imports_function
(
self
):
'''
'''
...
@@ -1046,8 +1040,7 @@ class CustomResponseTest(ResponseTest):
...
@@ -1046,8 +1040,7 @@ class CustomResponseTest(ResponseTest):
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
problem
.
grade_answers
({
'1_2_1'
:
'42'
})
except
ResponseError
:
except
ResponseError
:
self
.
fail
(
"Could not use name '
%
s' in custom response"
self
.
fail
(
"Could not use name '{0}s' in custom response"
.
format
(
module_name
))
%
module_name
)
class
SchematicResponseTest
(
ResponseTest
):
class
SchematicResponseTest
(
ResponseTest
):
...
...
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