Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
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
OpenEdx
pystache_custom
Commits
e00931d4
Commit
e00931d4
authored
Dec 16, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished fleshing out the initial docstrings for the context module.
parent
c8defb3f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
pystache/context.py
+18
-8
tests/test_context.py
+8
-0
No files found.
pystache/context.py
View file @
e00931d4
...
...
@@ -106,14 +106,24 @@ class Context(object):
"""
Query the stack for the given key, and return the resulting value.
Querying for a key queries objects in the stack in order from
last-added objects to first (last in, first out).
Querying an item in the stack is done as follows:
(1) The __getitem__ method is attempted first, if it exists.
This method returns None if no item in the stack contains the key.
Querying for a key queries items in the stack in order from last-
added objects to first (last in, first out). The value returned
is the value of the key for the first item for which the item
contains the key. If the key is not found in any item in the
stack, then this method returns the default value. The default
value defaults to None.
Querying an item in the stack is done in the following way:
(1) If the item defines __getitem__() and the item contains the
key (i.e. __contains__() returns True), then the corresponding
value is returned.
(2) Otherwise, the method looks for an attribute with the same
name as the key. If such an attribute exists, the value of
this attribute is returned. If the attribute is callable,
however, the attribute is first called with no arguments.
(3) If there is no attribute with the same name as the key, then
the key is considered not found in the item.
"""
for
obj
in
reversed
(
self
.
_stack
):
...
...
tests/test_context.py
View file @
e00931d4
...
...
@@ -105,6 +105,14 @@ class GetItemTestCase(TestCase):
obj
=
SimpleObject
()
self
.
assertNotFound
(
obj
,
"missing"
)
def
test_object__attribute_is_callable
(
self
):
"""
Test getting a callable attribute from an object.
"""
obj
=
SimpleObject
()
self
.
assertEquals
(
_get_item
(
obj
,
"foo_callable"
),
"called..."
)
### Case: obj implements __getitem__() (i.e. a "mapping object").
def
test_mapping__key_present
(
self
):
...
...
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