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

zopefoundation / ZODB / 5595761575

pending completion
5595761575

push

github

web-flow
Drop support for Python < 3.7 (#386)

* Bumped version for breaking release.

* Drop support for Python 2.7, 3.5, 3.6.

---------

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

2877 of 4050 branches covered (71.04%)

554 of 554 new or added lines in 89 files covered. (100.0%)

13323 of 15914 relevant lines covered (83.72%)

0.84 hits per line

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

73.33
/src/ZODB/tests/testPersistentMapping.py
1
##############################################################################
2
#
3
# Copyright (c) 2001, 2002 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
"""Verify that PersistentMapping works with old versions of Zope.
1✔
15

16
The comments in PersistentMapping.py address the issue in some detail.
17
The pickled form of a PersistentMapping must use _container to store
18
the actual mapping, because old versions of Zope used this attribute.
19
If the new code doesn't generate pickles that are consistent with the
20
old code, developers will have a hard time testing the new code.
21
"""
22

23
import sys
1✔
24
import unittest
1✔
25

26
import ZODB
1✔
27
from ZODB.Connection import TransactionMetaData
1✔
28
from ZODB.MappingStorage import MappingStorage
1✔
29

30

31
# This pickle contains a persistent mapping pickle created from the
32
# old code.
33
pickle = ('((U\x0bPersistenceq\x01U\x11PersistentMappingtq\x02Nt.}q\x03U\n'
1✔
34
          '_containerq\x04}q\x05U\x07versionq\x06U\x03oldq\x07ss.\n')
35

36

37
class PMTests(unittest.TestCase):
1✔
38

39
    def testOldStyleRoot(self):
1✔
40
        # The Persistence module doesn't exist in Zope3's idea of what ZODB
41
        # is, but the global `pickle` references it explicitly.  So just
42
        # bail if Persistence isn't available.
43
        try:
1✔
44
            import Persistence  # noqa:  F401 'Persistence' imported but unused
1✔
45
        except ImportError:
46
            return
47
        # insert the pickle in place of the root
48
        s = MappingStorage()
×
49
        t = TransactionMetaData()
×
50
        s.tpc_begin(t)
×
51
        s.store('\000' * 8, None, pickle, '', t)
×
52
        s.tpc_vote(t)
×
53
        s.tpc_finish(t)
×
54

55
        db = ZODB.DB(s)
×
56
        # If the root can be loaded successfully, we should be okay.
57
        r = db.open().root()
×
58
        # But make sure it looks like a new mapping
59
        self.assertTrue(hasattr(r, 'data'))
×
60
        self.assertTrue(not hasattr(r, '_container'))
×
61

62
    def testBackwardCompat(self):
1✔
63
        # Verify that the sanest of the ZODB 3.2 dotted paths still works.
64
        from persistent.mapping import PersistentMapping as newPath
1✔
65

66
        from ZODB.PersistentMapping import PersistentMapping as oldPath
1✔
67

68
        self.assertTrue(oldPath is newPath)
1✔
69

70
    def testBasicOps(self):
1✔
71
        from persistent.mapping import PersistentMapping
1✔
72
        m = PersistentMapping({'x': 1}, a=2, b=3)
1✔
73
        m['name'] = 'bob'
1✔
74
        self.assertEqual(m['name'], "bob")
1✔
75
        self.assertEqual(m.get('name', 42), "bob")
1✔
76
        self.assertTrue('name' in m)
1✔
77

78
        try:
1✔
79
            m['fred']
1✔
80
        except KeyError:
1✔
81
            pass
1✔
82
        else:
83
            self.fail("expected KeyError")
84
        self.assertTrue('fred' not in m)
1✔
85
        self.assertEqual(m.get('fred'), None)
1✔
86
        self.assertEqual(m.get('fred', 42), 42)
1✔
87

88
        keys = sorted(m.keys())
1✔
89
        self.assertEqual(keys, ['a', 'b', 'name', 'x'])
1✔
90

91
        values = set(m.values())
1✔
92
        self.assertEqual(values, {1, 2, 3, 'bob'})
1✔
93

94
        items = sorted(m.items())
1✔
95
        self.assertEqual(items,
1✔
96
                         [('a', 2), ('b', 3), ('name', 'bob'), ('x', 1)])
97

98
    # PersistentMapping didn't have an __iter__ method before ZODB 3.4.2.
99
    # Check that it plays well now with the Python iteration protocol.
100
    def testIteration(self):
1✔
101
        from persistent.mapping import PersistentMapping
1✔
102
        m = PersistentMapping({'x': 1}, a=2, b=3)
1✔
103
        m['name'] = 'bob'
1✔
104

105
        def check(keylist):
1✔
106
            keylist.sort()
1✔
107
            self.assertEqual(keylist, ['a', 'b', 'name', 'x'])
1✔
108

109
        check(list(m))
1✔
110
        check([key for key in m])
1✔
111

112
        i = iter(m)
1✔
113
        keylist = []
1✔
114
        while 1:
115
            try:
1✔
116
                key = next(i)
1✔
117
            except StopIteration:
1✔
118
                break
1✔
119
            keylist.append(key)
1✔
120
        check(keylist)
1✔
121

122

123
def find_global(modulename, classname):
1✔
124
    """Helper for this test suite to get special PersistentMapping"""
125

126
    if classname == "PersistentMapping":
×
127
        class PersistentMapping:
×
128
            def __setstate__(self, state):
×
129
                self.__dict__.update(state)
×
130
        return PersistentMapping
×
131
    else:
132
        __import__(modulename)
×
133
        mod = sys.modules[modulename]
×
134
        return getattr(mod, classname)
×
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

© 2026 Coveralls, Inc