Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rely on BTrees 4.8 and don't manually test for it as a Mapping. #114

Merged
merged 1 commit into from Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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