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

zopefoundation / Zope / 3956162881

pending completion
3956162881

push

github

Michael Howitz
Update to deprecation warning free releases.

4401 of 7036 branches covered (62.55%)

Branch coverage included in aggregate %.

27161 of 31488 relevant lines covered (86.26%)

0.86 hits per line

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

92.59
/src/Products/Five/tests/test_size.py
1
##############################################################################
2
#
3
# Copyright (c) 2004, 2005 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
"""Size adapters for testing
1✔
15
"""
16
from zope.interface import implementer
1✔
17
from zope.size.interfaces import ISized
1✔
18

19

20
@implementer(ISized)
1✔
21
class SimpleContentSize:
1✔
22
    """Size for ``SimpleContent`` objects."""
23

24
    def __init__(self, context):
1✔
25
        self.context = context
1✔
26

27
    def sizeForSorting(self):
1✔
28
        return ('byte', 42)
1✔
29

30
    def sizeForDisplay(self):
1✔
31
        return "What is the meaning of life?"
×
32

33

34
@implementer(ISized)
1✔
35
class FancyContentSize:
1✔
36
    """Size for ``SimpleContent`` objects."""
37

38
    def __init__(self, context):
1✔
39
        self.context = context
1✔
40

41
    def sizeForSorting(self):
1✔
42
        return ('line', 143)
1✔
43

44
    def sizeForDisplay(self):
1✔
45
        return "That's not the meaning of life!"
×
46

47

48
def test_size():
1✔
49
    """
50
    Test size adapters
51

52
    Set up:
53

54
      >>> from zope.component.testing import setUp, tearDown
55
      >>> setUp()
56

57
      >>> configure_zcml = '''
58
      ... <configure xmlns="http://namespaces.zope.org/zope"
59
      ...            xmlns:five="http://namespaces.zope.org/five">
60
      ...   <five:sizable
61
      ...    class="Products.Five.tests.testing.simplecontent.SimpleContent" />
62
      ...   <five:sizable
63
      ...    class="Products.Five.tests.testing.fancycontent.FancyContent" />
64
      ...   <adapter
65
      ...       for="Products.Five.tests.testing.simplecontent.ISimpleContent"
66
      ...       provides="zope.size.interfaces.ISized"
67
      ...       factory="Products.Five.tests.test_size.SimpleContentSize"
68
      ...       />
69
      ...   <adapter
70
      ...       for="Products.Five.tests.testing.fancycontent.IFancyContent"
71
      ...       provides="zope.size.interfaces.ISized"
72
      ...       factory="Products.Five.tests.test_size.FancyContentSize"
73
      ...       />
74
      ... </configure>'''
75

76
      >>> import Products.Five
77
      >>> from Zope2.App import zcml
78
      >>> zcml.load_config('meta.zcml', Products.Five)
79
      >>> zcml.load_string(configure_zcml)
80
      >>> folder = self.folder  # NOQA: F821
81

82
      >>> from Products.Five.tests.testing.simplecontent import (
83
      ... manage_addSimpleContent)
84
      >>> from Products.Five.tests.testing.fancycontent import (
85
      ... manage_addFancyContent)
86

87
    We have registered an ``ISized`` adapter for SimpleContent:
88

89
      >>> n = manage_addSimpleContent(folder, 'simple', 'Simple')
90
      >>> folder.simple.get_size()
91
      42
92

93
    Fancy content already has a ``get_size`` method
94

95
      >>> n = manage_addFancyContent(folder, 'fancy', 'Fancy')
96
      >>> folder.fancy.get_size()
97
      43
98

99
    Clean up:
100

101
      >>> tearDown()
102
    """
103

104

105
def test_suite():
1✔
106
    from Testing.ZopeTestCase import ZopeDocTestSuite
1✔
107
    return ZopeDocTestSuite()
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