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
4aa4c514
Commit
4aa4c514
authored
Jan 15, 2014
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add i18n attribute to LoncapaSystem
[LMS-1597]
parent
d2146978
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
2 deletions
+30
-2
common/lib/capa/capa/capa_problem.py
+7
-1
common/lib/capa/capa/responsetypes.py
+2
-1
common/lib/capa/capa/tests/__init__.py
+2
-0
common/lib/capa/capa/tests/test_responsetypes.py
+18
-0
common/lib/xmodule/xmodule/capa_base.py
+1
-0
No files found.
common/lib/capa/capa/capa_problem.py
View file @
4aa4c514
...
...
@@ -71,7 +71,11 @@ class LoncapaSystem(object):
can provide these resources however make sense for their environment, and
this code can remain independent.
See :class:`ModuleSystem` for documentation of these attributes.
Attributes:
i18n: an object implementing the `gettext.Translations` interface so
that we can use `.ugettext` to localize strings.
See :class:`ModuleSystem` for documentation of other attributes.
"""
def
__init__
(
# pylint: disable=invalid-name
...
...
@@ -82,6 +86,7 @@ class LoncapaSystem(object):
can_execute_unsafe_code
,
DEBUG
,
# pylint: disable=invalid-name
filestore
,
i18n
,
node_path
,
render_template
,
seed
,
# Why do we do this if we have self.seed?
...
...
@@ -94,6 +99,7 @@ class LoncapaSystem(object):
self
.
can_execute_unsafe_code
=
can_execute_unsafe_code
self
.
DEBUG
=
DEBUG
# pylint: disable=invalid-name
self
.
filestore
=
filestore
self
.
i18n
=
i18n
self
.
node_path
=
node_path
self
.
render_template
=
render_template
self
.
seed
=
seed
# Why do we do this if we have self.seed?
...
...
common/lib/capa/capa/responsetypes.py
View file @
4aa4c514
...
...
@@ -875,8 +875,9 @@ class NumericalResponse(LoncapaResponse):
correct_ans
=
evaluator
({},
{},
self
.
correct_answer
)
except
Exception
:
log
.
debug
(
"Content error--answer '
%
s' is not a valid number"
,
self
.
correct_answer
)
_
=
self
.
capa_system
.
i18n
.
ugettext
raise
StudentInputError
(
"There was a problem with the staff answer to this problem"
_
(
"There was a problem with the staff answer to this problem"
)
)
return
correct_ans
...
...
common/lib/capa/capa/tests/__init__.py
View file @
4aa4c514
"""Tools for helping with testing capa."""
import
gettext
import
os
import
os.path
...
...
@@ -41,6 +42,7 @@ def test_capa_system():
can_execute_unsafe_code
=
lambda
:
False
,
DEBUG
=
True
,
filestore
=
fs
.
osfs
.
OSFS
(
os
.
path
.
join
(
TEST_DIR
,
"test_files"
)),
i18n
=
gettext
.
NullTranslations
(),
node_path
=
os
.
environ
.
get
(
"NODE_PATH"
,
"/usr/local/lib/node_modules"
),
render_template
=
tst_render_template
,
seed
=
0
,
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
4aa4c514
...
...
@@ -1140,6 +1140,24 @@ class NumericalResponseTest(ResponseTest):
"Content error--answer '
%
s' is not a valid number"
,
staff_ans
)
@mock.patch
(
'capa.responsetypes.log'
)
def
test_responsetype_i18n
(
self
,
mock_log
):
"""Test that LoncapaSystem has an i18n that works."""
staff_ans
=
"clearly bad syntax )[+1e"
problem
=
self
.
build_problem
(
answer
=
staff_ans
,
tolerance
=
1e-3
)
class
FakeTranslations
(
object
):
"""A fake gettext.Translations object."""
def
ugettext
(
self
,
text
):
"""Return the 'translation' of `text`."""
if
text
==
"There was a problem with the staff answer to this problem"
:
text
=
"TRANSLATED!"
return
text
problem
.
capa_system
.
i18n
=
FakeTranslations
()
with
self
.
assertRaisesRegexp
(
StudentInputError
,
"TRANSLATED!"
):
self
.
assert_grade
(
problem
,
'1+j'
,
'correct'
)
def
test_grade_infinity
(
self
):
"""
Check that infinity doesn't automatically get marked correct.
...
...
common/lib/xmodule/xmodule/capa_base.py
View file @
4aa4c514
...
...
@@ -267,6 +267,7 @@ class CapaMixin(CapaFields):
can_execute_unsafe_code
=
self
.
system
.
can_execute_unsafe_code
,
DEBUG
=
self
.
system
.
DEBUG
,
filestore
=
self
.
system
.
filestore
,
i18n
=
self
.
system
.
service
(
self
,
"i18n"
),
node_path
=
self
.
system
.
node_path
,
render_template
=
self
.
system
.
render_template
,
seed
=
self
.
system
.
seed
,
# Why do we do this if we have self.seed?
...
...
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