• 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

97.78
/src/ZPublisher/tests/test_mapply.py
1
##############################################################################
2
#
3
# Copyright (c) 2007 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

15
import unittest
1✔
16

17
import Acquisition
1✔
18
import ExtensionClass
1✔
19
from ZPublisher.mapply import mapply
1✔
20

21

22
class MapplyTests(unittest.TestCase):
1✔
23

24
    def testMethod(self):
1✔
25

26
        def compute(a, b, c=4):
1✔
27
            return '%d%d%d' % (a, b, c)
1✔
28

29
        values = {'a': 2, 'b': 3, 'c': 5}
1✔
30
        v = mapply(compute, (), values)
1✔
31
        self.assertEqual(v, '235')
1✔
32

33
        v = mapply(compute, (7,), values)
1✔
34
        self.assertEqual(v, '735')
1✔
35

36
    def testClass(self):
1✔
37
        values = {'a': 2, 'b': 3, 'c': 5}
1✔
38

39
        class c:
1✔
40
            a = 3
1✔
41

42
            def __call__(self, b, c=4):
1✔
43
                return '%d%d%d' % (self.a, b, c)
1✔
44

45
            compute = __call__
1✔
46

47
        cc = c()
1✔
48
        v = mapply(cc, (), values)
1✔
49
        self.assertEqual(v, '335')
1✔
50

51
        del values['c']
1✔
52
        v = mapply(cc.compute, (), values)
1✔
53
        self.assertEqual(v, '334')
1✔
54

55
    def testObjectWithCall(self):
1✔
56
        # Make sure that the __call__ of an object can also be another
57
        # callable object.  mapply will do the right thing and
58
        # recursive look for __call__ attributes until it finds an
59
        # actual method:
60

61
        class CallableObject:
1✔
62
            def __call__(self, a, b):
1✔
63
                return f'{a}{b}'
1✔
64

65
        class Container:
1✔
66
            __call__ = CallableObject()
1✔
67

68
        v = mapply(Container(), (8, 3), {})
1✔
69
        self.assertEqual(v, '83')
1✔
70

71
    def testUncallableObject(self):
1✔
72
        # Normally, mapply will raise a TypeError if it encounters an
73
        # uncallable object (e.g. an interger ;))
74
        self.assertRaises(TypeError, mapply, 2, (), {})
1✔
75

76
        # Unless you enable the 'maybe' flag, in which case it will
77
        # only maybe call the object
78
        self.assertEqual(mapply(2, (), {}, maybe=True), 2)
1✔
79

80
    def testNoCallButAcquisition(self):
1✔
81
        # Make sure that mapply won't erroneously walk up the
82
        # Acquisition chain when looking for __call__ attributes:
83

84
        class Root(ExtensionClass.Base):
1✔
85
            def __call__(self):
1✔
86
                return 'The root __call__'
×
87

88
        class NoCallButAcquisition(Acquisition.Implicit):
1✔
89
            pass
1✔
90

91
        ob = NoCallButAcquisition().__of__(Root())
1✔
92
        self.assertRaises(TypeError, mapply, ob, (), {})
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