• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / zope.proxy / 16098813542

18 Feb 2025 08:01AM UTC coverage: 99.941% (+0.002%) from 99.939%
16098813542

push

github

web-flow
Update Python version support. (#74)

* Drop support for Python 3.8.
* Add preliminary support for Python 3.14.

---------

Co-authored-by: Jens Vagelpohl <jens@plyp.com>

213 of 213 branches covered (100.0%)

Branch coverage included in aggregate %.

1481 of 1482 relevant lines covered (99.93%)

6.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/zope/proxy/tests/test_decorator.py
1
##############################################################################
2
#
3
# Copyright (c) 2003 Zope Foundation and Contributors.
4
# All Rights Reserved.
5
#
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
12
#
13
##############################################################################
14
"""Test Harness
7✔
15
"""
16
import unittest
7✔
17

18

19
class DecoratorSpecificationDescriptorTests(unittest.TestCase):
7✔
20

21
    def _getTargetClass(self):
7✔
22
        from zope.proxy.decorator import DecoratorSpecificationDescriptor
7✔
23
        return DecoratorSpecificationDescriptor
7✔
24

25
    def _makeOne(self):
7✔
26
        return self._getTargetClass()()
7✔
27

28
    def test___get___w_class(self):
7✔
29
        from zope.interface import Interface
7✔
30
        from zope.interface import implementer
7✔
31
        from zope.interface import provider
7✔
32

33
        class IContextFactory(Interface):
7✔
34
            pass
7✔
35

36
        class IContext(Interface):
7✔
37
            pass
7✔
38

39
        @provider(IContextFactory)
7✔
40
        @implementer(IContext)
7✔
41
        class Context:
7✔
42
            pass
7✔
43
        dsd = self._makeOne()
7✔
44
        self.assertEqual(list(dsd.__get__(None, Context)), [IContextFactory])
7✔
45

46
    def test___get___w_inst_no_proxy(self):
7✔
47
        from zope.interface import Interface
7✔
48
        from zope.interface import implementer
7✔
49
        from zope.interface import provider
7✔
50

51
        class IContextFactory(Interface):
7✔
52
            pass
7✔
53

54
        class IContext(Interface):
7✔
55
            pass
7✔
56

57
        @provider(IContextFactory)
7✔
58
        @implementer(IContext)
7✔
59
        class Context:
7✔
60
            pass
7✔
61
        dsd = self._makeOne()
7✔
62
        self.assertEqual(list(dsd.__get__(Context(), None)), [IContext])
7✔
63

64
    def test___get___w_inst_w_proxy(self):
7✔
65
        from zope.interface import Interface
7✔
66
        from zope.interface import implementer
7✔
67
        from zope.interface import provider
7✔
68

69
        from zope.proxy import ProxyBase
7✔
70

71
        class IContextFactory(Interface):
7✔
72
            pass
7✔
73

74
        class IContext(Interface):
7✔
75
            pass
7✔
76

77
        @provider(IContextFactory)
7✔
78
        @implementer(IContext)
7✔
79
        class Context:
7✔
80
            pass
7✔
81
        context = Context()
7✔
82
        proxy = ProxyBase(context)
7✔
83
        dsd = self._makeOne()
7✔
84
        self.assertEqual(list(dsd.__get__(proxy, None)), [IContext])
7✔
85

86
    def test___get___w_inst_w_derived_proxy(self):
7✔
87
        from zope.interface import Interface
7✔
88
        from zope.interface import implementer
7✔
89
        from zope.interface import provider
7✔
90

91
        from zope.proxy import ProxyBase
7✔
92

93
        class IContextFactory(Interface):
7✔
94
            pass
7✔
95

96
        class IContext(Interface):
7✔
97
            pass
7✔
98

99
        @provider(IContextFactory)
7✔
100
        @implementer(IContext)
7✔
101
        class Context:
7✔
102
            pass
7✔
103

104
        class IProxyFactory(Interface):
7✔
105
            pass
7✔
106

107
        class IProxy(Interface):
7✔
108
            pass
7✔
109

110
        @provider(IProxyFactory)
7✔
111
        @implementer(IProxy)
7✔
112
        class Proxy(ProxyBase):
7✔
113
            pass
7✔
114
        context = Context()
7✔
115
        proxy = Proxy(context)
7✔
116
        dsd = self._makeOne()
7✔
117
        self.assertEqual(list(dsd.__get__(proxy, None)),
7✔
118
                         [IContext, IProxy])
119

120
    def test___set___not_allowed(self):
7✔
121
        from zope.interface import Interface
7✔
122
        from zope.interface import implementer
7✔
123

124
        class IFoo(Interface):
7✔
125
            pass
7✔
126

127
        @implementer(IFoo)
7✔
128
        class Foo:
7✔
129
            pass
7✔
130
        foo = Foo()
7✔
131
        dsd = self._makeOne()
7✔
132
        self.assertRaises(TypeError, dsd.__set__, foo, object())
7✔
133

134

135
class SpecificationDecoratorBaseTests(unittest.TestCase):
7✔
136

137
    def _getTargetClass(self):
7✔
138
        from zope.proxy.decorator import SpecificationDecoratorBase
7✔
139
        return SpecificationDecoratorBase
7✔
140

141
    def _makeOne(self, wrapped):
7✔
142
        return self._getTargetClass()(wrapped)
7✔
143

144
    def test_wrapped_instance(self):
7✔
145
        from zope.interface import Interface
7✔
146
        from zope.interface import implementer
7✔
147
        from zope.interface import providedBy
7✔
148

149
        class IFoo(Interface):
7✔
150
            pass
7✔
151

152
        @implementer(IFoo)
7✔
153
        class Foo:
7✔
154
            pass
7✔
155
        foo = Foo()
7✔
156
        proxy = self._makeOne(foo)
7✔
157
        self.assertEqual(list(providedBy(proxy)), list(providedBy(foo)))
7✔
158

159
    def test_proxy_that_provides_interface_as_well_as_wrapped(self):
7✔
160
        # If both the wrapper and the wrapped object provide
161
        # interfaces, the wrapper provides the sum
162
        from zope.interface import Interface
7✔
163
        from zope.interface import implementer
7✔
164
        from zope.interface import providedBy
7✔
165

166
        class IFoo(Interface):
7✔
167
            pass
7✔
168

169
        @implementer(IFoo)
7✔
170
        class Foo:
7✔
171
            from_foo = 1
7✔
172

173
        class IWrapper(Interface):
7✔
174
            pass
7✔
175

176
        @implementer(IWrapper)
7✔
177
        class Proxy(self._getTargetClass()):
7✔
178
            pass
7✔
179

180
        foo = Foo()
7✔
181
        proxy = Proxy(foo)
7✔
182

183
        self.assertEqual(proxy.from_foo, 1)
7✔
184
        self.assertEqual(list(providedBy(proxy)), [IFoo, IWrapper])
7✔
185

186

187
def test_suite():
7✔
188
    return unittest.TestSuite((
7✔
189
        unittest.defaultTestLoader.loadTestsFromTestCase(
190
            DecoratorSpecificationDescriptorTests),
191
        unittest.defaultTestLoader.loadTestsFromTestCase(
192
            SpecificationDecoratorBaseTests),
193
    ))
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc