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
10bba6f1
Commit
10bba6f1
authored
Jan 22, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished view.Locator.get_template() (though still need auxiliary methods).
parent
2976f997
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
18 deletions
+88
-18
pystache/view.py
+31
-4
tests/common.py
+8
-0
tests/test_context.py
+1
-11
tests/test_view.py
+48
-3
No files found.
pystache/view.py
View file @
10bba6f1
...
@@ -5,6 +5,8 @@ This module provides a View class.
...
@@ -5,6 +5,8 @@ This module provides a View class.
"""
"""
import
os.path
from
.context
import
Context
from
.context
import
Context
from
.locator
import
Locator
from
.locator
import
Locator
from
.renderer
import
Renderer
from
.renderer
import
Renderer
...
@@ -112,12 +114,37 @@ class Locator(object):
...
@@ -112,12 +114,37 @@ class Locator(object):
"""
"""
def
__init__
(
self
):
def
__init__
(
self
,
reader
):
pass
self
.
reader
=
reader
# TODO: unit test
def
get_relative_template_location
(
self
,
view
):
"""
Return the relative template path as a (dir, file_name) pair.
"""
if
view
.
template_path
is
not
None
:
return
os
.
path
.
split
(
view
.
template_path
)
# TODO: finish this
return
None
# TODO: unit test
def
get_template_path
(
self
,
view
):
"""
Return the path to the view's associated template.
"""
if
view
.
template_path
is
not
None
:
return
os
.
path
.
split
(
view
.
template_path
)
# TODO: finish this
return
None
def
get_template
(
self
,
view
):
def
get_template
(
self
,
view
):
if
view
.
template
is
not
None
:
if
view
.
template
is
not
None
:
return
view
.
template
return
view
.
template
# TODO: locate template
path
=
self
.
get_template_path
(
view
)
return
None
return
self
.
reader
.
read
(
path
)
tests/common.py
View file @
10bba6f1
...
@@ -27,3 +27,11 @@ def assert_strings(test_case, actual, expected):
...
@@ -27,3 +27,11 @@ def assert_strings(test_case, actual, expected):
test_case
.
assertEquals
(
actual
,
expected
,
message
)
test_case
.
assertEquals
(
actual
,
expected
,
message
)
class
AssertIsMixin
:
"""A mixin for adding assertIs() to a unittest.TestCase."""
# unittest.assertIs() is not available until Python 2.7:
# http://docs.python.org/library/unittest.html#unittest.TestCase.assertIsNone
def
assertIs
(
self
,
first
,
second
):
self
.
assertTrue
(
first
is
second
,
msg
=
"
%
s is not
%
s"
%
(
repr
(
first
),
repr
(
second
)))
tests/test_context.py
View file @
10bba6f1
...
@@ -11,7 +11,7 @@ import unittest
...
@@ -11,7 +11,7 @@ import unittest
from
pystache.context
import
_NOT_FOUND
from
pystache.context
import
_NOT_FOUND
from
pystache.context
import
_get_value
from
pystache.context
import
_get_value
from
pystache.context
import
Context
from
pystache.context
import
Context
from
tests.common
import
AssertIsMixin
class
SimpleObject
(
object
):
class
SimpleObject
(
object
):
...
@@ -39,16 +39,6 @@ class DictLike(object):
...
@@ -39,16 +39,6 @@ class DictLike(object):
return
self
.
_dict
[
key
]
return
self
.
_dict
[
key
]
class
AssertIsMixin
:
"""A mixin for adding assertIs() to a unittest.TestCase."""
# unittest.assertIs() is not available until Python 2.7:
# http://docs.python.org/library/unittest.html#unittest.TestCase.assertIsNone
def
assertIs
(
self
,
first
,
second
):
self
.
assertTrue
(
first
is
second
,
msg
=
"
%
s is not
%
s"
%
(
repr
(
first
),
repr
(
second
)))
class
GetValueTests
(
unittest
.
TestCase
,
AssertIsMixin
):
class
GetValueTests
(
unittest
.
TestCase
,
AssertIsMixin
):
"""Test context._get_value()."""
"""Test context._get_value()."""
...
...
tests/test_view.py
View file @
10bba6f1
...
@@ -7,6 +7,7 @@ from examples.lambdas import Lambdas
...
@@ -7,6 +7,7 @@ from examples.lambdas import Lambdas
from
examples.inverted
import
Inverted
,
InvertedLists
from
examples.inverted
import
Inverted
,
InvertedLists
from
pystache.view
import
View
from
pystache.view
import
View
from
pystache.view
import
Locator
from
pystache.view
import
Locator
from
tests.common
import
AssertIsMixin
class
Thing
(
object
):
class
Thing
(
object
):
...
@@ -170,15 +171,59 @@ class ViewTestCase(unittest.TestCase):
...
@@ -170,15 +171,59 @@ class ViewTestCase(unittest.TestCase):
self
.
assertEquals
(
view
.
render
(),
"""one, two, three, empty list"""
)
self
.
assertEquals
(
view
.
render
(),
"""one, two, three, empty list"""
)
class
LocatorTests
(
unittest
.
TestCase
):
class
LocatorTests
(
unittest
.
TestCase
,
AssertIsMixin
):
def
_make_locator
(
self
):
def
_make_locator
(
self
):
locator
=
Locator
()
class
MockReader
(
object
):
def
read
(
self
,
path
):
return
"read:
%
s"
%
repr
(
path
)
reader
=
MockReader
()
locator
=
Locator
(
reader
=
reader
)
return
locator
return
locator
def
test_get_template
(
self
):
def
test_init__reader
(
self
):
reader
=
"reader"
# in practice, this is a reader instance.
locator
=
Locator
(
reader
)
self
.
assertIs
(
locator
.
reader
,
reader
)
# TODO: make this test real
def
test_get_relative_template_location__template_path__file_name
(
self
):
locator
=
self
.
_make_locator
()
view
=
View
()
view
.
template_path
=
'foo.txt'
self
.
assertEquals
(
locator
.
get_relative_template_location
(
view
),
(
''
,
'foo.txt'
))
# TODO: make this test real
def
test_get_relative_template_location__template_path__full_path
(
self
):
locator
=
self
.
_make_locator
()
view
=
View
()
view
.
template_path
=
'foo.txt'
self
.
assertEquals
(
locator
.
get_relative_template_location
(
view
),
(
''
,
'foo.txt'
))
def
test_get_template__template_attribute_set
(
self
):
"""
Test get_template() with view.template set to a non-None value.
"""
locator
=
self
.
_make_locator
()
locator
=
self
.
_make_locator
()
view
=
View
()
view
=
View
()
view
.
template
=
'foo'
view
.
template
=
'foo'
self
.
assertEquals
(
locator
.
get_template
(
view
),
'foo'
)
self
.
assertEquals
(
locator
.
get_template
(
view
),
'foo'
)
def
test_get_template__template_attribute_not_set
(
self
):
"""
Test get_template() with view.template set to None.
"""
locator
=
self
.
_make_locator
()
locator
.
get_template_path
=
lambda
view
:
"path"
view
=
View
()
view
.
template
=
None
self
.
assertEquals
(
locator
.
get_template
(
view
),
"read: 'path'"
)
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