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

zopefoundation / zope.component / 4397327696

pending completion
4397327696

push

github

Jens Vagelpohl
- use cheaper check as suggested by @teythoon

468 of 489 branches covered (95.71%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

4620 of 4625 relevant lines covered (99.89%)

1.0 hits per line

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

99.02
/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.
1✔
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.testfiles.views import IC
1✔
24

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

28
class ITestType(IInterface):
1✔
29
    pass
1✔
30

31

32
class I1(Interface):
1✔
33
    pass
1✔
34

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

38
class I3(Interface):
1✔
39
    pass
1✔
40

41
class I4(Interface):
1✔
42
    pass
1✔
43

44
class IGI(Interface):
1✔
45
    pass
1✔
46

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

50
class ISI(Interface):
1✔
51
    pass
1✔
52

53
class ISII(Interface):
1✔
54
    pass
1✔
55

56
class U(object):
1✔
57

58
    def __init__(self, name):
1✔
59
        self.__name__ = name
1✔
60

61
    def __repr__(self):
1✔
62
        return "%s(%s)" % (self.__class__.__name__, self.__name__)
1✔
63

64
@implementer(I1)
1✔
65
class U1(U):
1✔
66
    pass
1✔
67

68
@implementer(I1, I2)
1✔
69
class U12(U):
1✔
70
    pass
1✔
71

72
@adapter(I1)
1✔
73
def handle1(x):
1✔
74
    write('handle1 %s' % x)
1✔
75

76
def handle2(*objects):
1✔
77
    write( 'handle2 ' + repr(objects))
1✔
78

79
@adapter(I1)
1✔
80
def handle3(x):
1✔
81
    write( 'handle3 %s' % x)
1✔
82

83
@adapter(I1)
1✔
84
def handle4(x):
1✔
85
    write( 'handle4 %s' % x)
1✔
86

87
class GlobalRegistry:
1✔
88
    pass
1✔
89

90
from zope.component.globalregistry import GlobalAdapterRegistry
1✔
91
base = GlobalAdapterRegistry(GlobalRegistry, 'adapters')
1✔
92
GlobalRegistry.adapters = base
1✔
93
def clear_base():
1✔
94
    base.__init__(GlobalRegistry, 'adapters')
1✔
95

96

97
@implementer(I1)
1✔
98
class Ob(object):
1✔
99
    def __repr__(self):
1✔
100
        return '<instance Ob>'
1✔
101

102

103
ob = Ob()
1✔
104

105
@implementer(I2)
1✔
106
class Ob2(object):
1✔
107
    def __repr__(self):
1✔
108
        return '<instance Ob2>'
1✔
109

110
@implementer(IC)
1✔
111
class Ob3(object):
1✔
112
    pass
1✔
113

114
@implementer(I2)
1✔
115
class Comp(object):
1✔
116
    def __init__(self, context):
1✔
117
        self.context = context
1✔
118

119
comp = Comp(1)
1✔
120

121

122
class ConformsToIComponentLookup(object):
1✔
123
    """Allow a dummy sitemanager to conform/adapt to `IComponentLookup`."""
124

125
    def __init__(self, sitemanager):
1✔
126
        self.sitemanager = sitemanager
1✔
127

128
    def __conform__(self, interface):
1✔
129
        """This method is specified by the adapter PEP to do the adaptation."""
130
        from zope.interface.interfaces import IComponentLookup
1✔
131
        if interface is IComponentLookup:
1!
132
            return self.sitemanager
1✔
133

134

135
def clearZCML(test=None):
1✔
136
    from zope.configuration.xmlconfig import XMLConfig
1✔
137
    import zope.component
1✔
138
    from zope.component.testing import setUp
1✔
139
    from zope.component.testing import tearDown
1✔
140
    tearDown()
1✔
141
    setUp()
1✔
142
    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