From 0f960245604ea273bd15b655006ff8cc4f957a6d Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Wed, 11 Jul 2018 10:24:01 -0500 Subject: [PATCH 1/3] Enable testing on Python 3.7 --- .travis.yml | 25 ++++++++++++++----------- setup.py | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index f846356..09e83d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,19 @@ language: python sudo: false -python: - - 2.7 - - 3.6 - - pypy - - pypy3 -matrix: - include: - - python: 2.7 - env: PURE_PYTHON=1 - - python: 3.6 - env: PURE_PYTHON=1 +group: travis_latest +language: python +jobs: + include: + - python: 2.7 # 2.7.14 pip 9.0.1 + - python: 3.6 # 3.6.3 pip 9.0.1 + - python: 3.7 # 3.7.0 pip 10.0.1 + dist: xenial + - python: pypy # 2.7.13 pip 9.0.1 + - python: pypy3 # 3.5.3 pip 9.0.1 + - python: 2.7 + env: PURE_PYTHON=1 + - python: 3.6 + env: PURE_PYTHON=1 env: global: - CC="ccache gcc" diff --git a/setup.py b/setup.py index 69356da..8a43a88 100755 --- a/setup.py +++ b/setup.py @@ -139,8 +139,8 @@ def _c(m): 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', ], From f08b42f04564cfce238b8e0362106c32f54653bb Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Wed, 11 Jul 2018 10:26:02 -0500 Subject: [PATCH 2/3] Maybe need sudo for 3.7 right now --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 09e83d3..18badbb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ jobs: - python: 3.6 # 3.6.3 pip 9.0.1 - python: 3.7 # 3.7.0 pip 10.0.1 dist: xenial + sudo: true - python: pypy # 2.7.13 pip 9.0.1 - python: pypy3 # 3.5.3 pip 9.0.1 - python: 2.7 From 082344b10c60b5c4890d493a1ddad2777456c4cc Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Wed, 11 Jul 2018 11:05:03 -0500 Subject: [PATCH 3/3] Fix tests and deprecations on Python 3.7 --- .../externalization/_externalizer.pxd | 1 - .../externalization/externalizer.py | 13 ++++--- .../internalization/externals.py | 5 ++- .../internalization/updater.py | 8 +++-- src/nti/externalization/persistence.py | 35 +++++++++++-------- .../externalization/tests/test_persistence.py | 13 +++++-- .../tests/test_representation.py | 8 ++--- 7 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/nti/externalization/externalization/_externalizer.pxd b/src/nti/externalization/externalization/_externalizer.pxd index 7a1979e..22799f6 100644 --- a/src/nti/externalization/externalization/_externalizer.pxd +++ b/src/nti/externalization/externalization/_externalizer.pxd @@ -6,7 +6,6 @@ from nti.externalization.__base_interfaces cimport LocatedExternalDict as LED from nti.externalization.externalization._decorate cimport decorate_external_object # Imports -cdef collections cdef defaultdict cdef six cdef numbers diff --git a/src/nti/externalization/externalization/externalizer.py b/src/nti/externalization/externalization/externalizer.py index d82675e..5df2de4 100644 --- a/src/nti/externalization/externalization/externalizer.py +++ b/src/nti/externalization/externalization/externalizer.py @@ -14,8 +14,14 @@ from __future__ import print_function # stdlib imports -import collections import warnings +try: + from collections.abc import Set + from collections.abc import Mapping +except ImportError: + from collections import Set + from collections import Mapping +from collections import defaultdict from weakref import WeakKeyDictionary import BTrees.OOBTree @@ -42,7 +48,6 @@ logger = __import__('logging').getLogger(__name__) -defaultdict = collections.defaultdict # It turns out that the name we use for externalization (and really the registry, too) # we must keep thread-local. We call into objects without any context, @@ -63,7 +68,7 @@ #: to be directly externalized. SEQUENCE_TYPES = ( persistent.list.PersistentList, - collections.Set, + Set, list, tuple, ) @@ -73,7 +78,7 @@ MAPPING_TYPES = ( persistent.mapping.PersistentMapping, BTrees.OOBTree.OOBTree, - collections.Mapping + Mapping ) diff --git a/src/nti/externalization/internalization/externals.py b/src/nti/externalization/internalization/externals.py index 7a010d3..f7e42f8 100644 --- a/src/nti/externalization/internalization/externals.py +++ b/src/nti/externalization/internalization/externals.py @@ -14,7 +14,10 @@ # stdlib imports -from collections import MutableSequence +try: + from collections.abc import MutableSequence +except ImportError: + from collections import MutableSequence from zope import component diff --git a/src/nti/externalization/internalization/updater.py b/src/nti/externalization/internalization/updater.py index 8d37801..73ace4e 100644 --- a/src/nti/externalization/internalization/updater.py +++ b/src/nti/externalization/internalization/updater.py @@ -11,8 +11,12 @@ # stdlib imports -from collections import MutableSequence -from collections import MutableMapping +try: + from collections.abc import MutableSequence + from collections.abc import MutableMapping +except ImportError: + from collections import MutableSequence + from collections import MutableMapping import inspect import warnings diff --git a/src/nti/externalization/persistence.py b/src/nti/externalization/persistence.py index e25de67..4988be0 100644 --- a/src/nti/externalization/persistence.py +++ b/src/nti/externalization/persistence.py @@ -9,7 +9,15 @@ from __future__ import print_function # stdlib imports -import collections +try: + from collections.abc import Sequence +except ImportError: + from collections import Sequence + +try: + from itertools import izip +except ImportError: + izip = zip import persistent from persistent.list import PersistentList @@ -86,16 +94,15 @@ def setPersistentStateChanged(obj): def _weakRef_toExternalObject(self): val = self() - if val is not None: - return toExternalObject(val) + return toExternalObject(val) if val is not None else None + PWeakRef.toExternalObject = _weakRef_toExternalObject interface.classImplements(PWeakRef, IExternalObject) def _weakRef_toExternalOID(self): val = self() - if val is not None: - return toExternalOID(val) + return toExternalOID(val) if val is not None else None PWeakRef.toExternalOID = _weakRef_toExternalOID @@ -176,17 +183,17 @@ def __getitem__(self, i): def __eq__(self, other): # If we just compare lists, weak refs will fail badly # if they're compared with non-weak refs - if not isinstance(other, collections.Sequence): + if not isinstance(other, Sequence): return False - result = False - if len(self) == len(other): - result = True - for i in range(len(self)): - if self[i] != other[i]: - result = False - break - return result + if len(self) != len(other): + return False + + for obj1, obj2 in izip(self, other): + if obj1 != obj2: + return False + + return True def __wrap(self, obj): return obj if isinstance(obj, PWeakRef) else PWeakRef(obj) diff --git a/src/nti/externalization/tests/test_persistence.py b/src/nti/externalization/tests/test_persistence.py index 15dd752..cb88dae 100644 --- a/src/nti/externalization/tests/test_persistence.py +++ b/src/nti/externalization/tests/test_persistence.py @@ -95,6 +95,17 @@ def test_mutate(self): obj.remove(pers2) assert_that(obj, is_([])) + def test_equality(self): + + obj = PersistentExternalizableWeakList() + pers = Persistent() + obj.append(pers) + + assert_that(obj, is_([pers])) + assert_that(obj, is_not([pers, pers])) + assert_that(obj, is_not([])) + assert_that(obj, is_not([self])) + class TestPersistentExternalizableDict(unittest.TestCase): def test_to_external_dict(self): @@ -162,7 +173,6 @@ class P(Persistent): def toExternalObject(self, **kwargs): return {'a': 42} - p = P() wref = PWeakRef(P()) assert_that(wref.toExternalObject(), is_({'a': 42})) @@ -173,7 +183,6 @@ class P(Persistent): def toExternalOID(self, **kwargs): return b'abc' - p = P() wref = PWeakRef(P()) assert_that(wref.toExternalOID(), is_(b'abc')) diff --git a/src/nti/externalization/tests/test_representation.py b/src/nti/externalization/tests/test_representation.py index 703fa1a..507246b 100644 --- a/src/nti/externalization/tests/test_representation.py +++ b/src/nti/externalization/tests/test_representation.py @@ -58,7 +58,7 @@ class Foo(object): def test_raises_POSError(self): def raise_(self): from ZODB.POSException import ConnectionStateError - raise ConnectionStateError("CSE") + raise ConnectionStateError() @representation.WithRepr(raise_) class Foo(object): @@ -67,11 +67,11 @@ class Foo(object): r = repr(Foo()) assert_that(r, is_("")) + "ConnectionStateError())>")) def test_raises_attribute_error(self): def raise_(self): - raise AttributeError("an attr") + raise AttributeError() @representation.WithRepr(raise_) class Foo(object): @@ -80,7 +80,7 @@ class Foo(object): r = repr(Foo()) assert_that(r, is_("")) + "AttributeError())>")) class TestYaml(unittest.TestCase):