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
a2c4948c
Commit
a2c4948c
authored
Apr 24, 2012
by
David Ormsbee
Committed by
Calen Pennington
Jun 07, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial commit for checker script that validates problem files
parent
698fea84
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
4 deletions
+94
-4
common/lib/capa/capa_problem.py
+3
-4
common/lib/capa/checker.py
+91
-0
No files found.
common/lib/capa/capa_problem.py
View file @
a2c4948c
...
...
@@ -174,10 +174,9 @@ class LoncapaProblem(object):
return
self
.
correct_map
def
get_question_answers
(
self
):
'''
Make a dict of (id,correct_answer) entries, for all the problems.
Called by "show answers" button JSON request (see capa_module)
'''
"""Returns a dict of answer_ids to answer values. If we can't generate
an answer (because it's a customresponse type), that answer_id is
not included."""
context
=
self
.
extract_context
(
self
.
tree
)
answer_map
=
dict
()
problems_simple
=
self
.
extract_problems
(
self
.
tree
)
# purified (flat) XML tree of just response queries
...
...
common/lib/capa/checker.py
0 → 100755
View file @
a2c4948c
#!/usr/bin/env python
"""
Commandline tool for doing operations on Problems
"""
import
argparse
import
logging
import
sys
from
cStringIO
import
StringIO
from
capa_problem
import
LoncapaProblem
logging
.
basicConfig
(
format
=
"
%(levelname)
s
%(message)
s"
)
log
=
logging
.
getLogger
(
'capa.checker'
)
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Check Problem Files'
)
parser
.
add_argument
(
"command"
,
choices
=
[
'test'
])
# Watch? Render? Open?
parser
.
add_argument
(
"files"
,
nargs
=
"+"
,
type
=
argparse
.
FileType
(
'r'
))
parser
.
add_argument
(
"--seed"
,
required
=
False
,
type
=
int
)
args
=
parser
.
parse_args
()
log
.
setLevel
(
logging
.
INFO
)
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
)
except
Exception
as
ex
:
log
.
error
(
"Could not parse file {0}"
.
format
(
problem_file
.
name
))
log
.
exception
(
ex
)
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
))
# 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
):
"""Split this up so that we're only used for formula/numeric answers.
Examples of where this fails:
* Displayed answers use units but acceptable ones do not.
- L1e0.xml
- Presents itself as UndefinedVariable (when it tries to pass to calc)
* "a or d" is what's displayed, but only "a" or "d" is accepted, not the
string "a or d".
- L1-e00.xml
"""
answers
=
problem
.
get_question_answers
()
log
.
debug
(
answers
)
if
answers
:
try
:
results
=
problem
.
grade_answers
(
answers
)
log
.
debug
(
results
)
assert
(
all
(
result
==
'correct'
for
result
in
results
.
values
()))
except
AssertionError
:
log
.
error
(
"The following generated answers were not accepted:"
)
for
question_id
,
result
in
sorted
(
results
.
items
()):
if
result
!=
'correct'
:
log
.
error
(
" {0} = {1}"
.
format
(
question_id
,
answers
[
question_id
]))
except
Exception
as
ex
:
log
.
exception
(
ex
)
if
__name__
==
'__main__'
:
sys
.
exit
(
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