File: test_location.py

package info (click to toggle)
python-pyramid 1.10.2+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,052 kB
  • sloc: python: 42,982; makefile: 41
file content (51 lines) | stat: -rw-r--r-- 1,388 bytes parent folder | download
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
import unittest
from zope.interface import implementer
from pyramid.interfaces import ILocation


class TestInside(unittest.TestCase):
    def _callFUT(self, one, two):
        from pyramid.location import inside

        return inside(one, two)

    def test_inside(self):
        o1 = Location()
        o2 = Location()
        o2.__parent__ = o1
        o3 = Location()
        o3.__parent__ = o2
        o4 = Location()
        o4.__parent__ = o3

        self.assertEqual(self._callFUT(o1, o1), True)
        self.assertEqual(self._callFUT(o2, o1), True)
        self.assertEqual(self._callFUT(o3, o1), True)
        self.assertEqual(self._callFUT(o4, o1), True)
        self.assertEqual(self._callFUT(o1, o4), False)
        self.assertEqual(self._callFUT(o1, None), False)


class TestLineage(unittest.TestCase):
    def _callFUT(self, context):
        from pyramid.location import lineage

        return lineage(context)

    def test_lineage(self):
        o1 = Location()
        o2 = Location()
        o2.__parent__ = o1
        o3 = Location()
        o3.__parent__ = o2
        o4 = Location()
        o4.__parent__ = o3
        result = list(self._callFUT(o3))
        self.assertEqual(result, [o3, o2, o1])
        result = list(self._callFUT(o1))
        self.assertEqual(result, [o1])


@implementer(ILocation)
class Location(object):
    __name__ = __parent__ = None