File: test_decorator.py

package info (click to toggle)
python-pyramid 2.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,612 kB
  • sloc: python: 41,526; makefile: 28
file content (53 lines) | stat: -rw-r--r-- 1,394 bytes parent folder | download | duplicates (2)
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
import inspect
import unittest


class TestReify(unittest.TestCase):
    def _makeOne(self, wrapped):
        from pyramid.decorator import reify

        return reify(wrapped)

    def test___get__withinst(self):
        def wrapped(inst):
            return 'a'

        decorator = self._makeOne(wrapped)
        inst = Dummy()
        result = decorator.__get__(inst)
        self.assertEqual(result, 'a')
        self.assertEqual(inst.__dict__['wrapped'], 'a')

    def test___get__noinst(self):
        def wrapped(inst):
            return 'a'  # pragma: no cover

        decorator = self._makeOne(wrapped)
        result = decorator.__get__(None)
        self.assertEqual(result, decorator)

    def test_copy_docstring(self):
        def wrapped(inst):
            """Test doc"""
            return 'a'  # pragma: no cover

        decorator = self._makeOne(wrapped)
        assert decorator.__doc__ == 'Test doc'

    def test_not_function(self):
        """
        Because reify'd methods act as attributes, it's important that they
        aren't recognized as a function.  Otherwise tools like Sphinx may
        misbehave, like in https://github.com/Pylons/pyramid/issues/3655

        """

        def wrapped(inst):
            return 'a'  # pragma: no cover

        decorator = self._makeOne(wrapped)
        assert not inspect.isfunction(decorator)


class Dummy:
    pass