Skip to content

Commit

Permalink
Merge pull request #114 from NextThought/issue111
Browse files Browse the repository at this point in the history
Rely on BTrees 4.8 and don't manually test for it as a Mapping.
  • Loading branch information
jamadden committed Apr 14, 2021
2 parents 1d12a97 + b3ceb54 commit d363057
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -8,6 +8,8 @@

- Add support for Python 3.9.

- Depend on BTrees 4.8 and above. This simplifies externalization
checks. See `issue 111 <https://github.com/NextThought/nti.externalization/issues/111>`_.

2.1.0 (2020-08-03)
==================
Expand Down
9 changes: 4 additions & 5 deletions src/nti/externalization/externalization/externalizer.py
Expand Up @@ -81,11 +81,10 @@

#: The types that we will treat as mappings for externalization purposes. These
#: all map onto a dict.
MAPPING_TYPES = (
persistent.mapping.PersistentMapping,
BTrees.OOBTree.OOBTree,
Mapping
)
#: .. versionchanged:: 2.2.0
#: Now only the ABC Mapping is included. Previously BTrees and PersistentMapping
#: were special cased. But with BTrees 4.8.0, this is no longer needed.
MAPPING_TYPES = (Mapping,)



Expand Down
23 changes: 23 additions & 0 deletions src/nti/externalization/tests/test_externalization.py
Expand Up @@ -821,6 +821,29 @@ def toExternalObject(self, *args, **kwargs):
s = to_json_representation_externalized(result)
assert_that(s, is_('{"Class": "O", "Creator": "creator"}'))

def test_externalize_OOBTree(self):
from BTrees import family64
bt = family64.OO.BTree()
bt['key'] = 'value'
result = toExternalObject(bt)
assert_that(result, is_(dict))
assert_that(result, is_({'Class': 'OOBTree', 'key': 'value'}))

def test_externalize_PersistentMapping(self):
from persistent.mapping import PersistentMapping
pm = PersistentMapping()
pm['key'] = 'value'
result = toExternalObject(pm)
assert_that(result, is_(dict))
assert_that(result, is_({'Class': 'PersistentMapping', 'key': 'value'}))

def test_externalize_IIBTree(self):
from BTrees import family64
bt = family64.II.BTree()
bt[1] = 2
result = toExternalObject(bt)
assert_that(result, is_(dict))
assert_that(result, is_({'Class': 'LLBTree', 1: 2}))

@NoPickle
class DoNotPickleMe(object):
Expand Down

0 comments on commit d363057

Please sign in to comment.