commit | author | age
|
cbdc36
|
1 |
import unittest |
10ddb6
|
2 |
from zope.interface import implementer |
MM |
3 |
from pyramid.interfaces import ILocation |
cbdc36
|
4 |
|
0c29cf
|
5 |
|
e65927
|
6 |
class TestInside(unittest.TestCase): |
CM |
7 |
def _callFUT(self, one, two): |
b60bdb
|
8 |
from pyramid.location import inside |
0c29cf
|
9 |
|
e65927
|
10 |
return inside(one, two) |
0c29cf
|
11 |
|
cbdc36
|
12 |
def test_inside(self): |
CM |
13 |
o1 = Location() |
0c29cf
|
14 |
o2 = Location() |
MM |
15 |
o2.__parent__ = o1 |
|
16 |
o3 = Location() |
|
17 |
o3.__parent__ = o2 |
|
18 |
o4 = Location() |
|
19 |
o4.__parent__ = o3 |
cbdc36
|
20 |
|
e65927
|
21 |
self.assertEqual(self._callFUT(o1, o1), True) |
CM |
22 |
self.assertEqual(self._callFUT(o2, o1), True) |
|
23 |
self.assertEqual(self._callFUT(o3, o1), True) |
|
24 |
self.assertEqual(self._callFUT(o4, o1), True) |
|
25 |
self.assertEqual(self._callFUT(o1, o4), False) |
|
26 |
self.assertEqual(self._callFUT(o1, None), False) |
cbdc36
|
27 |
|
0c29cf
|
28 |
|
e65927
|
29 |
class TestLineage(unittest.TestCase): |
CM |
30 |
def _callFUT(self, context): |
b60bdb
|
31 |
from pyramid.location import lineage |
0c29cf
|
32 |
|
e65927
|
33 |
return lineage(context) |
cbdc36
|
34 |
|
CM |
35 |
def test_lineage(self): |
|
36 |
o1 = Location() |
0c29cf
|
37 |
o2 = Location() |
MM |
38 |
o2.__parent__ = o1 |
|
39 |
o3 = Location() |
|
40 |
o3.__parent__ = o2 |
|
41 |
o4 = Location() |
|
42 |
o4.__parent__ = o3 |
e65927
|
43 |
result = list(self._callFUT(o3)) |
cbdc36
|
44 |
self.assertEqual(result, [o3, o2, o1]) |
e65927
|
45 |
result = list(self._callFUT(o1)) |
cbdc36
|
46 |
self.assertEqual(result, [o1]) |
0c29cf
|
47 |
|
MM |
48 |
|
3b7334
|
49 |
@implementer(ILocation) |
cbdc36
|
50 |
class Location(object): |
CM |
51 |
__name__ = __parent__ = None |