forked from twisted/twisted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_roots.py
63 lines (55 loc) · 1.77 KB
/
test_roots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
from __future__ import absolute_import, division
from twisted.trial import unittest
from twisted.python import roots
class RootsTests(unittest.TestCase):
def testExceptions(self):
request = roots.Request()
try:
request.write(b"blah")
except NotImplementedError:
pass
else:
self.fail()
try:
request.finish()
except NotImplementedError:
pass
else:
self.fail()
def testCollection(self):
collection = roots.Collection()
collection.putEntity("x", 'test')
self.assertEqual(collection.getStaticEntity("x"),
'test')
collection.delEntity("x")
self.assertEqual(collection.getStaticEntity('x'),
None)
try:
collection.storeEntity("x", None)
except NotImplementedError:
pass
else:
self.fail()
try:
collection.removeEntity("x", None)
except NotImplementedError:
pass
else:
self.fail()
def testConstrained(self):
class const(roots.Constrained):
def nameConstraint(self, name):
return (name == 'x')
c = const()
self.assertIsNone(c.putEntity('x', 'test'))
self.assertRaises(roots.ConstraintViolation,
c.putEntity, 'y', 'test')
def testHomogenous(self):
h = roots.Homogenous()
h.entityType = int
h.putEntity('a', 1)
self.assertEqual(h.getStaticEntity('a'),1 )
self.assertRaises(roots.ConstraintViolation,
h.putEntity, 'x', 'y')