summaryrefslogtreecommitdiff
path: root/test/test_templite.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_templite.py')
-rw-r--r--test/test_templite.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/test/test_templite.py b/test/test_templite.py
index fd7a3393..436951af 100644
--- a/test/test_templite.py
+++ b/test/test_templite.py
@@ -3,8 +3,16 @@
from coverage.templite import Templite
import unittest
-class AnyOldObject:
- pass
+class AnyOldObject(object):
+ """Simple testing object.
+
+ Use keyword arguments in the constructor to set attributes on the object.
+
+ """
+ def __init__(self, **attrs):
+ for n, v in attrs.items():
+ setattr(self, n, v)
+
class TemplateTest(unittest.TestCase):
@@ -48,18 +56,15 @@ class TemplateTest(unittest.TestCase):
def test_attribute(self):
# Variables' attributes can be accessed with dots.
- obj = AnyOldObject()
- obj.a = "Ay"
+ obj = AnyOldObject(a="Ay")
self.try_render("{{obj.a}}", locals(), "Ay")
- obj2 = AnyOldObject()
- obj2.obj = obj
- obj2.b = "Bee"
+ obj2 = AnyOldObject(obj=obj, b="Bee")
self.try_render("{{obj2.obj.a}} {{obj2.b}}", locals(), "Ay Bee")
def test_member_function(self):
# Variables' member functions can be used, as long as they are nullary.
- class WithMemberFns:
+ class WithMemberFns(object):
def ditto(self):
return self.txt + self.txt
obj = WithMemberFns()