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

zopefoundation / zope.component / 16248888290

25 Jun 2025 07:38AM UTC coverage: 99.774%. Remained the same
16248888290

push

github

web-flow
Merge pull request #77 from adrian-zon/patch-1

Fix typo

241 of 252 branches covered (95.63%)

Branch coverage included in aggregate %.

4615 of 4615 relevant lines covered (100.0%)

1.0 hits per line

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

98.88
/src/zope/component/tests/examples.py
1
##############################################################################
2
#
3
# Copyright (c) 2001, 2002, 2009 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
"""Examples supporting Sphinx doctest snippets.
15
"""
16
import sys
1✔
17

18
from zope.interface import Interface
1✔
19
from zope.interface import implementer
1✔
20
from zope.interface.interfaces import IInterface
1✔
21

22
from zope.component._declaration import adapter
1✔
23
from zope.component.globalregistry import GlobalAdapterRegistry
1✔
24
from zope.component.testfiles.views import IC
1✔
25

26

27
def write(x):
1✔
28
    sys.stdout.write('%s\n' % x)
1✔
29

30

31
class ITestType(IInterface):
1✔
32
    pass
1✔
33

34

35
class I1(Interface):
1✔
36
    pass
1✔
37

38

39
class I2(Interface):
1✔
40
    pass
1✔
41

42

43
class I3(Interface):
1✔
44
    pass
1✔
45

46

47
class I4(Interface):
1✔
48
    pass
1✔
49

50

51
class IGI(Interface):
1✔
52
    pass
1✔
53

54

55
class IQI(Interface):
1✔
56
    pass
1✔
57

58

59
class ISI(Interface):
1✔
60
    pass
1✔
61

62

63
class ISII(Interface):
1✔
64
    pass
1✔
65

66

67
class U:
1✔
68

69
    def __init__(self, name):
1✔
70
        self.__name__ = name
1✔
71

72
    def __repr__(self):
1✔
73
        return f"{self.__class__.__name__}({self.__name__})"
1✔
74

75

76
@implementer(I1)
1✔
77
class U1(U):
1✔
78
    pass
1✔
79

80

81
@implementer(I1, I2)
1✔
82
class U12(U):
1✔
83
    pass
1✔
84

85

86
@adapter(I1)
1✔
87
def handle1(x):
1✔
88
    write('handle1 %s' % x)
1✔
89

90

91
def handle2(*objects):
1✔
92
    write('handle2 ' + repr(objects))
1✔
93

94

95
@adapter(I1)
1✔
96
def handle3(x):
1✔
97
    write('handle3 %s' % x)
1✔
98

99

100
@adapter(I1)
1✔
101
def handle4(x):
1✔
102
    write('handle4 %s' % x)
1✔
103

104

105
class GlobalRegistry:
1✔
106
    pass
1✔
107

108

109
base = GlobalAdapterRegistry(GlobalRegistry, 'adapters')
1✔
110
GlobalRegistry.adapters = base
1✔
111

112

113
def clear_base():
1✔
114
    base.__init__(GlobalRegistry, 'adapters')
1✔
115

116

117
@implementer(I1)
1✔
118
class Ob:
1✔
119
    def __repr__(self):
1✔
120
        return '<instance Ob>'
1✔
121

122

123
ob = Ob()
1✔
124

125

126
@implementer(I2)
1✔
127
class Ob2:
1✔
128
    def __repr__(self):
1✔
129
        return '<instance Ob2>'
1✔
130

131

132
@implementer(IC)
1✔
133
class Ob3:
1✔
134
    pass
1✔
135

136

137
@implementer(I2)
1✔
138
class Comp:
1✔
139
    def __init__(self, context):
1✔
140
        self.context = context
1✔
141

142

143
comp = Comp(1)
1✔
144

145

146
class ConformsToIComponentLookup:
1✔
147
    """Allow a dummy sitemanager to conform/adapt to `IComponentLookup`."""
148

149
    def __init__(self, sitemanager):
1✔
150
        self.sitemanager = sitemanager
1✔
151

152
    def __conform__(self, interface):
1✔
153
        """This method is specified by the adapter PEP to do the adaptation."""
154
        from zope.interface.interfaces import IComponentLookup
1✔
155
        if interface is IComponentLookup:
1!
156
            return self.sitemanager
1✔
157

158

159
def clearZCML(test=None):
1✔
160
    from zope.configuration.xmlconfig import XMLConfig
1✔
161

162
    import zope.component
1✔
163
    from zope.component.testing import setUp
1✔
164
    from zope.component.testing import tearDown
1✔
165
    tearDown()
1✔
166
    setUp()
1✔
167
    XMLConfig('meta.zcml', zope.component)()
1✔
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