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
08c4032b
Commit
08c4032b
authored
Apr 01, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed View dependency from more examples and test cases.
parent
de8aed53
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
39 deletions
+72
-39
examples/partials_with_lambdas.py
+3
-4
examples/simple.py
+2
-3
examples/template_partial.py
+10
-5
tests/common.py
+4
-0
tests/test_examples.py
+18
-7
tests/test_simple.py
+20
-11
tests/test_template_spec.py
+15
-9
No files found.
examples/partials_with_lambdas.py
View file @
08c4032b
import
pystache
from
examples.lambdas
import
rot
class
PartialsWithLambdas
(
pystache
.
View
):
template_path
=
'examples'
class
PartialsWithLambdas
(
object
):
def
rot
(
self
):
return
rot
\ No newline at end of file
examples/simple.py
View file @
08c4032b
import
pystache
from
pystache
import
TemplateSpec
class
Simple
(
pystache
.
View
):
template_path
=
'examples'
class
Simple
(
TemplateSpec
):
def
thing
(
self
):
return
"pizza"
...
...
examples/template_partial.py
View file @
08c4032b
import
pystache
from
pystache
import
TemplateSpec
class
TemplatePartial
(
pystache
.
View
):
template_path
=
'examples'
class
TemplatePartial
(
TemplateSpec
):
def
__init__
(
self
,
renderer
):
self
.
renderer
=
renderer
def
_context_get
(
self
,
key
):
return
self
.
renderer
.
context
.
get
(
key
)
def
title
(
self
):
return
"Welcome"
...
...
@@ -13,4 +18,4 @@ class TemplatePartial(pystache.View):
return
[{
'item'
:
'one'
},
{
'item'
:
'two'
},
{
'item'
:
'three'
}]
def
thing
(
self
):
return
self
.
context
.
get
(
'prop'
)
\ No newline at end of file
return
self
.
_context_get
(
'prop'
)
\ No newline at end of file
tests/common.py
View file @
08c4032b
...
...
@@ -7,8 +7,12 @@ Provides test-related code that can be used by all tests.
import
os
import
examples
DATA_DIR
=
'tests/data'
EXAMPLES_DIR
=
os
.
path
.
dirname
(
examples
.
__file__
)
def
get_data_path
(
file_name
):
return
os
.
path
.
join
(
DATA_DIR
,
file_name
)
...
...
tests/test_examples.py
View file @
08c4032b
...
...
@@ -12,7 +12,8 @@ from examples.unicode_output import UnicodeOutput
from
examples.unicode_input
import
UnicodeInput
from
examples.nested_context
import
NestedContext
from
pystache
import
Renderer
from
tests.common
import
AssertStringMixin
from
.common
import
EXAMPLES_DIR
from
.common
import
AssertStringMixin
class
TestView
(
unittest
.
TestCase
,
AssertStringMixin
):
...
...
@@ -42,13 +43,19 @@ class TestView(unittest.TestCase, AssertStringMixin):
self
.
assertEquals
(
Unescaped
()
.
render
(),
"<h1>Bear > Shark</h1>"
)
def
test_template_partial
(
self
):
self
.
assertEquals
(
TemplatePartial
()
.
render
(),
"""<h1>Welcome</h1>
renderer
=
Renderer
(
search_dirs
=
EXAMPLES_DIR
)
actual
=
renderer
.
render
(
TemplatePartial
(
renderer
=
renderer
))
self
.
assertString
(
actual
,
u"""<h1>Welcome</h1>
Again, Welcome!"""
)
def
test_template_partial_extension
(
self
):
view
=
TemplatePartial
()
view
.
template_extension
=
'txt'
self
.
assertString
(
view
.
render
(),
u"""Welcome
renderer
=
Renderer
(
search_dirs
=
EXAMPLES_DIR
,
file_extension
=
'txt'
)
view
=
TemplatePartial
(
renderer
=
renderer
)
actual
=
renderer
.
render
(
view
)
self
.
assertString
(
actual
,
u"""Welcome
-------
## Again, Welcome! ##"""
)
...
...
@@ -77,9 +84,13 @@ Again, Welcome!""")
self
.
assertString
(
actual
,
u'it works!'
)
def
test_partial_in_partial_has_access_to_grand_parent_context
(
self
):
view
=
TemplatePartial
(
context
=
{
'prop'
:
'derp'
})
renderer
=
Renderer
(
search_dirs
=
EXAMPLES_DIR
)
view
=
TemplatePartial
(
renderer
=
renderer
)
view
.
template
=
'''{{>partial_in_partial}}'''
self
.
assertEquals
(
view
.
render
(),
'Hi derp!'
)
actual
=
renderer
.
render
(
view
,
{
'prop'
:
'derp'
})
self
.
assertEquals
(
actual
,
'Hi derp!'
)
if
__name__
==
'__main__'
:
unittest
.
main
()
tests/test_simple.py
View file @
08c4032b
...
...
@@ -8,7 +8,8 @@ from examples.lambdas import Lambdas
from
examples.template_partial
import
TemplatePartial
from
examples.simple
import
Simple
from
tests.common
import
AssertStringMixin
from
.common
import
EXAMPLES_DIR
from
.common
import
AssertStringMixin
class
TestSimple
(
unittest
.
TestCase
,
AssertStringMixin
):
...
...
@@ -26,8 +27,8 @@ class TestSimple(unittest.TestCase, AssertStringMixin):
context
=
Complex
()
renderer
=
Renderer
()
expected
=
renderer
.
render
(
template
,
context
)
self
.
assertEquals
(
expected
,
"Colors: red Colors: green Colors: blue "
)
actual
=
renderer
.
render
(
template
,
context
)
self
.
assertEquals
(
actual
,
"Colors: red Colors: green Colors: blue "
)
def
test_empty_context
(
self
):
template
=
'{{#empty_list}}Shouldnt see me {{/empty_list}}{{^empty_list}}Should see me{{/empty_list}}'
...
...
@@ -38,16 +39,21 @@ class TestSimple(unittest.TestCase, AssertStringMixin):
view
.
template
=
'{{#replace_foo_with_bar}}foo != bar. oh, it does!{{/replace_foo_with_bar}}'
renderer
=
Renderer
()
expected
=
renderer
.
render
(
view
)
self
.
assertString
(
expected
,
u'bar != bar. oh, it does!'
)
actual
=
renderer
.
render
(
view
)
self
.
assertString
(
actual
,
u'bar != bar. oh, it does!'
)
def
test_rendering_partial
(
self
):
view
=
TemplatePartial
()
renderer
=
Renderer
(
search_dirs
=
EXAMPLES_DIR
)
view
=
TemplatePartial
(
renderer
=
renderer
)
view
.
template
=
'{{>inner_partial}}'
self
.
assertEquals
(
view
.
render
(),
'Again, Welcome!'
)
actual
=
renderer
.
render
(
view
)
self
.
assertString
(
actual
,
u'Again, Welcome!'
)
view
.
template
=
'{{#looping}}{{>inner_partial}} {{/looping}}'
self
.
assertEquals
(
view
.
render
(),
'''Again, Welcome! Again, Welcome! Again, Welcome! '''
)
actual
=
renderer
.
render
(
view
)
self
.
assertString
(
actual
,
u"Again, Welcome! Again, Welcome! Again, Welcome! "
)
def
test_non_existent_value_renders_blank
(
self
):
view
=
Simple
()
...
...
@@ -66,9 +72,12 @@ class TestSimple(unittest.TestCase, AssertStringMixin):
In particular, this means that trailing newlines should be removed.
"""
view
=
TemplatePartial
()
view
.
template_extension
=
'txt'
self
.
assertString
(
view
.
render
(),
u"""Welcome
renderer
=
Renderer
(
search_dirs
=
EXAMPLES_DIR
,
file_extension
=
'txt'
)
view
=
TemplatePartial
(
renderer
=
renderer
)
actual
=
renderer
.
render
(
view
)
self
.
assertString
(
actual
,
u"""Welcome
-------
## Again, Welcome! ##"""
)
tests/test_template_spec.py
View file @
08c4032b
...
...
@@ -20,16 +20,14 @@ from pystache import View
from
pystache.template_spec
import
SpecLoader
from
pystache.locator
import
Locator
from
pystache.loader
import
Loader
from
.common
import
DATA_DIR
from
.common
import
EXAMPLES_DIR
from
.common
import
AssertIsMixin
from
.common
import
AssertStringMixin
from
.common
import
DATA_DIR
from
.data.views
import
SampleView
from
.data.views
import
NonAscii
EXAMPLES_DIR
=
os
.
path
.
dirname
(
examples
.
__file__
)
class
Thing
(
object
):
pass
...
...
@@ -78,13 +76,18 @@ class ViewTestCase(unittest.TestCase, AssertStringMixin):
self
.
assertEquals
(
view
.
render
(),
"Partial: No tags..."
)
def
test_basic_method_calls
(
self
):
view
=
Simple
()
self
.
assertEquals
(
view
.
render
(),
"Hi pizza!"
)
renderer
=
Renderer
()
actual
=
renderer
.
render
(
Simple
())
self
.
assertString
(
actual
,
u"Hi pizza!"
)
def
test_non_callable_attributes
(
self
):
view
=
Simple
()
view
.
thing
=
'Chris'
self
.
assertEquals
(
view
.
render
(),
"Hi Chris!"
)
renderer
=
Renderer
()
actual
=
renderer
.
render
(
view
)
self
.
assertEquals
(
actual
,
"Hi Chris!"
)
def
test_complex
(
self
):
renderer
=
Renderer
()
...
...
@@ -143,10 +146,13 @@ class ViewTestCase(unittest.TestCase, AssertStringMixin):
parent
=
Thing
()
parent
.
this
=
'derp'
parent
.
children
=
[
Thing
()]
view
=
Simple
(
context
=
{
'parent'
:
parent
}
)
view
=
Simple
()
view
.
template
=
"{{#parent}}{{#children}}{{this}}{{/children}}{{/parent}}"
self
.
assertEquals
(
view
.
render
(),
'derp'
)
renderer
=
Renderer
()
actual
=
renderer
.
render
(
view
,
{
'parent'
:
parent
})
self
.
assertString
(
actual
,
u'derp'
)
def
test_inverted_lists
(
self
):
renderer
=
Renderer
()
...
...
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