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
33b26577
Commit
33b26577
authored
Dec 17, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented (and tested) Context.top() and Context.copy().
parent
7a7d886e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
+45
-0
pystache/context.py
+21
-0
tests/test_context.py
+24
-0
No files found.
pystache/context.py
View file @
33b26577
...
@@ -137,8 +137,29 @@ class Context(object):
...
@@ -137,8 +137,29 @@ class Context(object):
return
default
return
default
def
push
(
self
,
item
):
def
push
(
self
,
item
):
"""
Push an item onto the stack.
"""
self
.
_stack
.
append
(
item
)
self
.
_stack
.
append
(
item
)
def
pop
(
self
):
def
pop
(
self
):
"""
Pop an item off of the stack, and return it.
"""
return
self
.
_stack
.
pop
()
return
self
.
_stack
.
pop
()
def
top
(
self
):
"""
Return the item last added to the stack.
"""
return
self
.
_stack
[
-
1
]
def
copy
(
self
):
"""
Return a copy of this instance.
"""
return
Context
(
*
self
.
_stack
)
tests/test_context.py
View file @
33b26577
...
@@ -242,3 +242,27 @@ class ContextTestCase(TestCase):
...
@@ -242,3 +242,27 @@ class ContextTestCase(TestCase):
self
.
assertEquals
(
item
,
{
"foo"
:
"buzz"
})
self
.
assertEquals
(
item
,
{
"foo"
:
"buzz"
})
self
.
assertEquals
(
context
.
get
(
key
),
"bar"
)
self
.
assertEquals
(
context
.
get
(
key
),
"bar"
)
def
test_top
(
self
):
key
=
"foo"
context
=
Context
({
key
:
"bar"
},
{
key
:
"buzz"
})
self
.
assertEquals
(
context
.
get
(
key
),
"buzz"
)
top
=
context
.
top
()
self
.
assertEquals
(
top
,
{
"foo"
:
"buzz"
})
# Make sure calling top() didn't remove the item from the stack.
self
.
assertEquals
(
context
.
get
(
key
),
"buzz"
)
def
test_copy
(
self
):
key
=
"foo"
original
=
Context
({
key
:
"bar"
},
{
key
:
"buzz"
})
self
.
assertEquals
(
original
.
get
(
key
),
"buzz"
)
new
=
original
.
copy
()
# Confirm that the copy behaves the same.
self
.
assertEquals
(
new
.
get
(
key
),
"buzz"
)
# Change the copy, and confirm it is changed.
new
.
pop
()
self
.
assertEquals
(
new
.
get
(
key
),
"bar"
)
# Confirm the original is unchanged.
self
.
assertEquals
(
original
.
get
(
key
),
"buzz"
)
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