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
02a2472d
Commit
02a2472d
authored
Apr 04, 2012
by
Rodrigo Bernardo Pimentel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved some more detailed tests into test_context.py
parent
ce47e5e4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
23 deletions
+39
-23
tests/test_context.py
+37
-1
tests/test_renderengine.py
+2
-22
No files found.
tests/test_context.py
View file @
02a2472d
...
...
@@ -11,7 +11,7 @@ import unittest
from
pystache.context
import
_NOT_FOUND
from
pystache.context
import
_get_value
from
pystache.context
import
Context
from
tests.common
import
AssertIsMixin
from
tests.common
import
AssertIsMixin
,
Attachable
class
SimpleObject
(
object
):
...
...
@@ -398,3 +398,39 @@ class ContextTests(unittest.TestCase, AssertIsMixin):
# Confirm the original is unchanged.
self
.
assertEquals
(
original
.
get
(
key
),
"buzz"
)
def
test_dot_notation__dict
(
self
):
key
=
"foo.bar"
original
=
Context
({
"foo"
:
{
"bar"
:
"baz"
}})
self
.
assertEquals
(
original
.
get
(
key
),
"baz"
)
# Works all the way down
key
=
"a.b.c.d.e.f.g"
original
=
Context
({
"a"
:
{
"b"
:
{
"c"
:
{
"d"
:
{
"e"
:
{
"f"
:
{
"g"
:
"w00t!"
}}}}}}})
self
.
assertEquals
(
original
.
get
(
key
),
"w00t!"
)
def
test_dot_notation__user_object
(
self
):
key
=
"foo.bar"
original
=
Context
({
"foo"
:
Attachable
(
bar
=
"baz"
)})
self
.
assertEquals
(
original
.
get
(
key
),
"baz"
)
# Works on multiple levels, too
key
=
"a.b.c.d.e.f.g"
Obj
=
Attachable
original
=
Context
({
"a"
:
Obj
(
b
=
Obj
(
c
=
Obj
(
d
=
Obj
(
e
=
Obj
(
f
=
Obj
(
g
=
"w00t!"
))))))})
self
.
assertEquals
(
original
.
get
(
key
),
"w00t!"
)
def
test_dot_notation__mixed_dict_and_obj
(
self
):
key
=
"foo.bar.baz.bak"
original
=
Context
({
"foo"
:
Attachable
(
bar
=
{
"baz"
:
Attachable
(
bak
=
42
)})})
self
.
assertEquals
(
original
.
get
(
key
),
42
)
def
test_dot_notation__missing_attr_or_key
(
self
):
key
=
"foo.bar.baz.bak"
original
=
Context
({
"foo"
:
{
"bar"
:
{}}})
self
.
assertEquals
(
original
.
get
(
key
),
None
)
original
=
Context
({
"foo"
:
Attachable
(
bar
=
Attachable
())})
self
.
assertEquals
(
original
.
get
(
key
),
None
)
tests/test_renderengine.py
View file @
02a2472d
...
...
@@ -456,31 +456,11 @@ class RenderTests(unittest.TestCase, AssertStringMixin):
def
test_dot_notation
(
self
):
"""
Check that we can use dot notation when the variable is a dict
or a used-defined object (or a combination of both)
Check that we can use dot notation when the variable is a dict
,
a used-defined object, or a combination of both
"""
# With a dict:
template
=
'Hello, {{person.name}}. I see you are {{person.details.age}}.'
context
=
{
'person'
:
{
'name'
:
'Biggles'
,
'details'
:
{
'age'
:
42
}}}
self
.
_assert_render
(
u'Hello, Biggles. I see you are 42.'
,
template
,
context
)
# With a user-defined object:
details
=
Attachable
(
age
=
42
)
person
=
Attachable
(
name
=
'Biggles'
,
details
=
details
)
template
=
'Hello, {{person.name}}. I see you are {{person.details.age}}.'
context
=
{
'person'
:
person
}
self
.
_assert_render
(
u'Hello, Biggles. I see you are 42.'
,
template
,
context
)
# All together now!
person
=
Attachable
(
name
=
'Biggles'
,
details
=
{
'age'
:
42
})
template
=
'Hello, {{person.name}}. I see you are {{person.details.age}}.'
context
=
{
'person'
:
person
}
self
.
_assert_render
(
u'Hello, Biggles. I see you are 42.'
,
template
,
context
)
# And the other way around:
details
=
Attachable
(
age
=
42
)
person
=
{
'name'
:
'Biggles'
,
'details'
:
details
}
template
=
'Hello, {{person.name}}. I see you are {{person.details.age}}.'
context
=
{
'person'
:
person
}
self
.
_assert_render
(
u'Hello, Biggles. I see you are 42.'
,
template
,
context
)
...
...
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