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
0a5e6ce6
Commit
0a5e6ce6
authored
Apr 25, 2012
by
David Ormsbee
Committed by
Calen Pennington
Jun 07, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A little refactoring to make clearer what running test on problem means
parent
d9e72b91
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
21 deletions
+32
-21
common/lib/capa/capa_problem.py
+4
-0
common/lib/capa/checker.py
+28
-21
No files found.
common/lib/capa/capa_problem.py
View file @
0a5e6ce6
...
...
@@ -12,6 +12,7 @@ import logging
import
math
import
numpy
import
os
import
os.path
import
random
import
re
import
scipy
...
...
@@ -125,6 +126,9 @@ class LoncapaProblem(object):
responder
=
response_types
[
response
.
tag
](
response
,
self
.
context
,
self
.
system
)
responder
.
preprocess_response
()
def
__unicode__
(
self
):
return
u"LoncapaProblem ({0})"
.
format
(
os
.
path
.
basename
(
self
.
filename
))
def
get_state
(
self
):
''' Stored per-user session data neeeded to:
1) Recreate the problem
...
...
common/lib/capa/checker.py
View file @
0a5e6ce6
...
...
@@ -2,6 +2,8 @@
"""
Commandline tool for doing operations on Problems
"""
from
__future__
import
unicode_literals
import
argparse
import
logging
import
os.path
...
...
@@ -26,12 +28,8 @@ def main():
args
=
parser
.
parse_args
()
log
.
setLevel
(
args
.
log_level
.
upper
())
old_stdout
=
sys
.
stdout
old_stderr
=
sys
.
stderr
for
problem_file
in
args
.
files
:
log
.
info
(
"Opening {0}"
.
format
(
problem_file
.
name
))
sys
.
stdout
=
problem_stdout
=
StringIO
()
sys
.
stderr
=
problem_stderr
=
StringIO
()
try
:
problem
=
LoncapaProblem
(
problem_file
.
name
,
"fakeid"
,
seed
=
args
.
seed
)
...
...
@@ -41,28 +39,31 @@ def main():
continue
if
args
.
command
==
'test'
:
test_problem
(
problem
)
log_captured_output
(
problem_stdout
,
"captured stdout from {0}"
.
format
(
problem_file
.
name
))
log_captured_output
(
problem_stderr
,
"captured stderr from {0}"
.
format
(
problem_file
.
name
))
command_test
(
problem
)
# Print captured problem prints
problem_file
.
close
()
sys
.
stdout
=
old_stdout
sys
.
stderr
=
old_stderr
# In case we want to do anything else here.
def
log_captured_output
(
output_stream
,
stream_name
):
output_stream
.
seek
(
0
)
output_text
=
output_stream
.
read
()
if
output_text
:
log
.
info
(
"##### Begin {0} #####
\n
"
.
format
(
stream_name
)
+
output_text
)
log
.
info
(
"##### End {0} #####"
.
format
(
stream_name
))
def
test_problem
(
problem
):
def
command_test
(
problem
):
# We're going to trap stdout/stderr from the problems (yes, some print)
old_stdout
,
old_stderr
=
sys
.
stdout
,
sys
.
stderr
try
:
sys
.
stdout
=
StringIO
()
sys
.
stderr
=
StringIO
()
check_that_suggested_answers_work
(
problem
)
log_captured_output
(
sys
.
stdout
,
"captured stdout from {0}"
.
format
(
problem
))
log_captured_output
(
sys
.
stderr
,
"captured stderr from {0}"
.
format
(
problem
))
except
Exception
as
e
:
log
.
exception
(
e
)
finally
:
sys
.
stdout
,
sys
.
stderr
=
old_stdout
,
old_stderr
def
check_that_suggested_answers_work
(
problem
):
"""Split this up so that we're only used for formula/numeric answers.
Examples of where this fails:
...
...
@@ -99,6 +100,12 @@ def test_problem(problem):
except
Exception
as
ex
:
log
.
exception
(
ex
)
def
log_captured_output
(
output_stream
,
stream_name
):
output_stream
.
seek
(
0
)
output_text
=
output_stream
.
read
()
if
output_text
:
log
.
info
(
"##### Begin {0} #####
\n
"
.
format
(
stream_name
)
+
output_text
)
log
.
info
(
"##### End {0} #####"
.
format
(
stream_name
))
if
__name__
==
'__main__'
:
...
...
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