1
# Copyright (c) 2004 Divmod.
2
# See LICENSE for details.
6
from nevow.testutil import TestCase
8
class TestProto(TestCase):
11
proto = stan.Proto(tagName)
12
self.assertEquals(tagName, str(proto))
14
def test_callCreatesTag(self):
15
proto = stan.Proto("hello")
16
tag = proto(world="1")
17
self.assertEquals(proto, tag.tagName)
18
self.assertEquals(tag.attributes['world'], '1')
20
def test_getItemCreatesTag(self):
21
proto = stan.Proto("hello")
23
self.assertEquals(proto, tag.tagName)
24
self.assertEquals(tag.children, [proto])
27
proto = stan.Proto("hello")
30
class TestTag(TestCase):
32
tag = proto(hello="world")["How are you"]
33
tag.fillSlots('foo', 'bar')
34
tag.filename = "foo/bar"
38
self.assertEquals(clone.attributes['hello'], 'world')
39
self.assertNotIdentical(clone.attributes, tag.attributes)
40
self.assertEquals(clone.children, ["How are you"])
41
self.assertNotIdentical(clone.children, tag.children)
42
self.assertEquals(tag.slotData, clone.slotData)
43
self.assertNotIdentical(tag.slotData, clone.slotData)
44
self.assertEqual(clone.filename, "foo/bar")
45
self.assertEqual(clone.lineNumber, 6)
46
self.assertEqual(clone.columnNumber, 12)
48
## TODO: need better clone test here to test clone(deep=True),
49
## and behavior of cloning nested lists.
52
tag = proto["these are", "children", "cool"]
54
self.assertEquals(tag.children, [])
56
def test_specials(self):
57
tag = proto(data=1, render=str, remember="stuff", key="myKey", **{'pattern': "item"})
58
self.assertEquals(tag.data, 1)
59
self.assertEquals(getattr(tag, 'render'), str)
60
self.assertEquals(tag.remember, "stuff")
61
self.assertEquals(tag.key, "myKey")
62
self.assertEquals(tag.pattern, "item")
67
Test that L{nevow.stan.visit} invokes the visitor it is given with all
68
the nodes in the DOM it is given in pre-order.
73
root = stan.Proto('root')()
74
firstChild = stan.Proto('firstChild')()
75
secondChild = stan.Proto('secondChild')()
76
firstGrandchild = stan.Proto('firstGrandchild')()
77
secondGrandchild = stan.Proto('secondGrandchild')()
78
thirdGrandchild = 'thirdGrandchild'
79
root[firstChild, secondChild]
80
secondChild[firstGrandchild, secondGrandchild, thirdGrandchild]
81
stan.visit(root, visitor)
84
[root, firstChild, secondChild,
85
firstGrandchild, secondGrandchild, thirdGrandchild])
89
class TestComment(TestCase):
91
def test_notCallable(self):
92
comment = stan.CommentProto()
93
self.assertRaises(NotImplementedError, comment, id='oops')
95
class TestUnderscore(TestCase):
96
def test_prefix(self):
97
proto = stan.Proto('div')
100
self.assertEquals(tag.attributes, {'class': 'a'})
102
def test_suffix(self):
103
proto = stan.Proto('div')
106
self.assertEquals(tag.attributes, {'class': 'a'})