diff options
author | Jason Madden <jamadden@gmail.com> | 2017-07-31 09:53:57 -0500 |
---|---|---|
committer | Jason Madden <jamadden@gmail.com> | 2017-07-31 09:53:57 -0500 |
commit | a021805a3afe4c140b0c8f42295da85a67d8752f (patch) | |
tree | 61bc027b9fe15b2d03a0128133693e42be91a974 | |
parent | 99049f39fbb012d2a7045aa1eec005cb1b5009e0 (diff) | |
download | zope-location-py36.tar.gz |
Add Python 3.6 and drop Python 3.3py36
- Badges
- Enable coveralls
- 100% coverage
- DRY with respect to dependencies in setup.py and tox.ini
- Remove _compat.py and use of its u() function since Python 3.2 is
dropped.
- Run doctests on all python versions.
-rw-r--r-- | .coveragerc | 11 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .travis.yml | 14 | ||||
-rw-r--r-- | CHANGES.rst | 54 | ||||
-rw-r--r-- | README.rst | 24 | ||||
-rw-r--r-- | docs/api.rst | 42 | ||||
-rw-r--r-- | docs/narr.rst | 42 | ||||
-rw-r--r-- | setup.cfg | 3 | ||||
-rw-r--r-- | setup.py | 70 | ||||
-rw-r--r-- | src/zope/__init__.py | 2 | ||||
-rw-r--r-- | src/zope/location/_compat.py | 24 | ||||
-rw-r--r-- | src/zope/location/interfaces.py | 9 | ||||
-rw-r--r-- | src/zope/location/pickling.py | 6 | ||||
-rw-r--r-- | src/zope/location/tests/test_configure.py | 39 | ||||
-rw-r--r-- | src/zope/location/tests/test_location.py | 28 | ||||
-rw-r--r-- | src/zope/location/tests/test_pickling.py | 79 | ||||
-rw-r--r-- | src/zope/location/traversing.py | 12 | ||||
-rw-r--r-- | tox.ini | 46 |
18 files changed, 235 insertions, 271 deletions
diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..51ab167 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,11 @@ +[run] +source = zope.location + +[report] +precision = 2 +exclude_lines = + pragma: no cover + if __name__ == '__main__': + raise NotImplementedError + self.fail + raise AssertionError @@ -11,3 +11,4 @@ docs/_build .coverage nosetests.xml coverage.xml +htmlcov/ diff --git a/.travis.yml b/.travis.yml index 2428b54..c26f0ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,14 +2,20 @@ language: python sudo: false python: - 2.7 - - 3.3 - 3.4 - 3.5 + - 3.6 - pypy - - pypy3 + - pypy3.5-5.8.0 install: - - pip install . + - pip install -U pip setuptools + - pip install -U coverage coveralls + - pip install -U -e .[test,docs] script: - - python setup.py test -q + - coverage run -m zope.testrunner --test-path=src + - coverage run -a -m sphinx -b doctest -d docs/_build/doctrees docs docs/_build/doctest +after_success: + - coveralls notifications: email: false +cache: pip diff --git a/CHANGES.rst b/CHANGES.rst index 2337da9..7ba8ed9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,20 +1,22 @@ -Changes -======= +========= + Changes +========= 4.1.0 (unreleased) ------------------- +================== -- Drop support for Python 2.6 and 3.2. +- Drop support for Python 2.6, 3.2 and 3.3. - Add a page to the docs on hacking ``zope.location``. - Note additional documentation dependencies. -- Add support for Python 3.5. +- Add support for Python 3.5 and 3.6. +- Remove internal ``_compat`` implementation module. 4.0.3 (2014-03-19) ------------------- +================== - Add Python 3.4 support. @@ -22,7 +24,7 @@ Changes 4.0.2 (2013-03-11) ------------------- +================== - Change the behavior of ``LocationProxy``'s ``__setattr__()`` to correctly behave when dealing with the pure Python version of the ``ProxyBase`` @@ -31,12 +33,12 @@ Changes 4.0.1 (2013-02-19) ------------------- +================== - Add Python 3.3 support. 4.0.0 (2012-06-07) ------------------- +================== - Remove backward-compatibility imports: @@ -78,24 +80,24 @@ Changes 3.9.1 (2011-08-22) ------------------- +================== - Add zcml extra as well as a test for configure.zcml. 3.9.0 (2009-12-29) ------------------- +================== - Move LocationCopyHook related tests to zope.copy and remove a test dependency on that package. 3.8.2 (2009-12-23) ------------------- +================== - Fix a typo in the configure.zcml. 3.8.1 (2009-12-23) ------------------- +================== - Remove dependency on zope.copy: the LocationCopyHook adapter is registered only if zope.copy is available. @@ -104,18 +106,18 @@ Changes has been deprecated. 3.8.0 (2009-12-22) ------------------- +================== - Adjust to testing output caused by new zope.schema. 3.7.1 (2009-11-18) ------------------- +================== - Move the IPossibleSite and ISite interfaces to zope.component as they are dealing with zope.component's concept of a site, but not with location. 3.7.0 (2009-09-29) ------------------- +================== - Add getParent() to ILocationInfo and moved the actual implementation here from zope.traversal.api, analogous to getParents(). @@ -128,7 +130,7 @@ Changes interdependency but is no longer used here. 3.6.0 (2009-08-27) ------------------- +================== - New feature release: deprecate locationCopy, CopyPersistent and PathPersistent from zope.location.pickling. These changes were already part @@ -138,13 +140,13 @@ Changes without using it. 3.5.5 (2009-08-15) ------------------- +================== - Add zope.deferredimport as a dependency as it's used directly by zope.location.pickling. 3.5.4 (2009-05-17) ------------------- +================== - Add ``IContained`` interface to ``zope.location.interfaces`` module. This interface was moved from ``zope.container`` (after @@ -153,22 +155,22 @@ Changes dependency cycles. 3.5.3 (2009-02-09) ------------------- +================== - Use new zope.copy package for implementing location copying. Thus there's changes in the ``zope.locaton.pickling`` module: - + * The ``locationCopy`` and ``CopyPersistent`` was removed in prefer to their equivalents in zope.copy. Deprecated backward-compatibility imports provided. - + * The module now provides a ``zope.copy.interfaces.ICopyHook`` adapter for ``ILocation`` objects that replaces the old CopyPersistent functionality of checking for the need to clone objects based on their location. 3.5.2 (2009-02-04) ------------------- +================== - Split RootPhysicallyLocatable adapter back from LocationPhysicallyLocatable, because the IRoot object may not always provide ILocation and the code @@ -177,7 +179,7 @@ Changes below with ``getParents`` method added (returns an empty list). 3.5.1 (2009-02-02) ------------------- +================== - Improve test coverage. @@ -197,12 +199,12 @@ Changes of retired zope3-dev at zope.org. 3.5.0 (2009-01-31) ------------------- +================== - Reverse the dependency between zope.location and zope.traversing. This also causes the dependency to various other packages go away. 3.4.0 (2007-10-02) ------------------- +================== - Initial release independent of the main Zope tree. @@ -1,15 +1,29 @@ -``zope.location`` -================= +=================== + ``zope.location`` +=================== .. image:: https://img.shields.io/pypi/v/zope.location.svg - :target: https://pypi.python.org/pypi/zope.location/ - :alt: Latest Version + :target: https://pypi.python.org/pypi/zope.location/ + :alt: Latest release + +.. image:: https://img.shields.io/pypi/pyversions/zope.location.svg + :target: https://pypi.org/project/zope.location/ + :alt: Supported Python versions .. image:: https://travis-ci.org/zopefoundation/zope.location.png?branch=master :target: https://travis-ci.org/zopefoundation/zope.location +.. image:: https://coveralls.io/repos/github/zopefoundation/zope.location/badge.svg?branch=master + :target: https://coveralls.io/github/zopefoundation/zope.location?branch=master + .. image:: https://readthedocs.org/projects/zopelocation/badge/?version=latest :target: http://zopelocation.readthedocs.org/en/latest/ :alt: Documentation Status -In Zope3, "locations" are special objects that have a structural location. +In Zope3, "locations" are special objects that have a structural +location, indicated with ``__name__`` and ``__parent__`` attributes. + +See `zope.container <https://zopecontainer.readthedocs.io/en/latest>`_ +for a useful extension of this concept to "containers." + +Documentation is hosted at https://zopelocation.readthedocs.io/en/latest/ diff --git a/docs/api.rst b/docs/api.rst index 2851dec..71fea5a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -57,7 +57,7 @@ .. automodule:: zope.location.traversing .. autoclass:: LocationPhysicallyLocatable - + .. doctest:: >>> from zope.interface.verify import verifyObject @@ -124,16 +124,16 @@ >>> from zope.location.traversing import LocationPhysicallyLocatable >>> root = Location() >>> directlyProvides(root, IRoot) - >>> LocationPhysicallyLocatable(root).getPath() - u'/' + >>> print(LocationPhysicallyLocatable(root).getPath()) + / >>> o1 = Location(); o1.__parent__ = root; o1.__name__ = 'o1' - >>> LocationPhysicallyLocatable(o1).getPath() - u'/o1' + >>> print(LocationPhysicallyLocatable(o1).getPath()) + /o1 >>> o2 = Location(); o2.__parent__ = o1; o2.__name__ = u'o2' - >>> LocationPhysicallyLocatable(o2).getPath() - u'/o1/o2' + >>> print(LocationPhysicallyLocatable(o2).getPath()) + /o1/o2 It is an error to get the path of a rootless location: @@ -203,10 +203,10 @@ >>> o2.__parent__ = o1 >>> LocationPhysicallyLocatable(o2).getParents() == [o1, root] True - + If the last parent is not an IRoot object, TypeError will be raised as statet before. - + >>> noLongerProvides(root, IRoot) >>> LocationPhysicallyLocatable(o2).getParents() Traceback (most recent call last): @@ -220,8 +220,8 @@ >>> from zope.location.location import Location >>> from zope.location.traversing import LocationPhysicallyLocatable >>> o1 = Location(); o1.__name__ = u'o1' - >>> LocationPhysicallyLocatable(o1).getName() - u'o1' + >>> print(LocationPhysicallyLocatable(o1).getName()) + o1 .. automethod:: getNearestSite @@ -246,18 +246,18 @@ >>> o1.__parent__ = root >>> LocationPhysicallyLocatable(o1).getNearestSite() is root True - + >>> directlyProvides(o1, ISite) >>> LocationPhysicallyLocatable(o1).getNearestSite() is o1 True - + >>> o2 = Location() >>> o2.__parent__ = o1 >>> LocationPhysicallyLocatable(o2).getNearestSite() is o1 True .. autoclass:: RootPhysicallyLocatable - + .. doctest:: >>> from zope.interface.verify import verifyObject @@ -269,7 +269,7 @@ .. automethod:: getRoot - No need to search for root when our context is already root :) + No need to search for root when our context is already root :) .. doctest:: @@ -280,14 +280,14 @@ .. automethod:: getPath - Root object is at the top of the tree, so always return ``/``. + Root object is at the top of the tree, so always return ``/``. .. doctest:: >>> from zope.location.traversing import RootPhysicallyLocatable >>> o1 = object() - >>> RootPhysicallyLocatable(o1).getPath() - u'/' + >>> print(RootPhysicallyLocatable(o1).getPath()) + / .. automethod:: getParent @@ -321,11 +321,11 @@ >>> from zope.location.traversing import RootPhysicallyLocatable >>> o1 = object() - >>> RootPhysicallyLocatable(o1).getName() - u'' + >>> RootPhysicallyLocatable(o1).getName() == u'' + True .. automethod:: getNearestSite - + Return object itself as the nearest site, because there's no other place to look for. It's also usual that the root is the site as well. diff --git a/docs/narr.rst b/docs/narr.rst index 8b311b1..3550384 100644 --- a/docs/narr.rst +++ b/docs/narr.rst @@ -4,8 +4,8 @@ Using :mod:`zope.location` :class:`~zope.location.location.Location` ----------------------------------------- -The `Location` base class is a mix-in that defines `__parent__` and -`__name__` attributes. +The ``Location`` base class is a mix-in that defines ``__parent__`` and +``__name__`` attributes. Usage within an Object field: @@ -16,23 +16,23 @@ Usage within an Object field: >>> from zope.schema.fieldproperty import FieldProperty >>> from zope.location.interfaces import ILocation >>> from zope.location.location import Location - + >>> class IA(Interface): ... location = Object(schema=ILocation, required=False, default=None) >>> @implementer(IA) ... class A(object): ... location = FieldProperty(IA['location']) - + >>> a = A() >>> a.location = Location() - + >>> loc = Location(); loc.__name__ = u'foo' >>> a.location = loc - + >>> loc = Location(); loc.__name__ = None >>> a.location = loc - - >>> loc = Location(); loc.__name__ = 'foo' + + >>> loc = Location(); loc.__name__ = b'foo' >>> a.location = loc Traceback (most recent call last): ... @@ -42,7 +42,7 @@ Usage within an Object field: :func:`~zope.location.location.inside` -------------------------------------- -The `inside` function tells if l1 is inside l2. L1 is inside l2 if l2 is an +The ``inside`` function tells if l1 is inside l2. L1 is inside l2 if l2 is an ancestor of l1. .. doctest:: @@ -51,7 +51,7 @@ ancestor of l1. >>> o2 = Location(); o2.__parent__ = o1 >>> o3 = Location(); o3.__parent__ = o2 >>> o4 = Location(); o4.__parent__ = o3 - + >>> from zope.location.location import inside >>> inside(o1, o1) @@ -65,10 +65,10 @@ ancestor of l1. >>> inside(o4, o1) True - + >>> inside(o1, o4) False - + >>> inside(o1, None) False @@ -76,8 +76,8 @@ ancestor of l1. :class:`~zope.location.location.LocationProxy` ---------------------------------------------- -`LocationProxy` is a non-picklable proxy that can be put around -objects that don't implement `ILocation`. +``LocationProxy`` is a non-picklable proxy that can be put around +objects that don't implement ``ILocation``. .. doctest:: @@ -94,7 +94,7 @@ objects that don't implement `ILocation`. 'Dad' >>> p.__name__ 'p' - + >>> import pickle >>> p2 = pickle.dumps(p) Traceback (most recent call last): @@ -136,13 +136,13 @@ This function allows us to iterate over object and all its parents. >>> o2.__parent__ = o1 >>> iter = LocationIterator(o3) - >>> iter.next() is o3 + >>> next(iter) is o3 True - >>> iter.next() is o2 + >>> next(iter) is o2 True - >>> iter.next() is o1 + >>> next(iter) is o1 True - >>> iter.next() + >>> next(iter) Traceback (most recent call last): ... StopIteration @@ -151,7 +151,7 @@ This function allows us to iterate over object and all its parents. :func:`~zope.location.location.located` --------------------------------------- -`located` locates an object in another and returns it: +``located`` locates an object in another and returns it: .. doctest:: @@ -182,7 +182,7 @@ If the object does not provide ILocation an adapter can be provided: >>> import zope.component >>> sm = zope.component.getGlobalSiteManager() >>> sm.registerAdapter(LocationProxy, required=(zope.interface.Interface,)) - + >>> l = [1, 2, 3] >>> parent = Location() >>> l_located = located(l, parent, 'l') @@ -9,3 +9,6 @@ where=src dev = develop easy_install zope.location[testing] docs = easy_install zope.location[docs] + +[bdist_wheel] +universal = 1 @@ -22,8 +22,26 @@ import os from setuptools import setup, find_packages def read(*rnames): - text = open(os.path.join(os.path.dirname(__file__), *rnames)).read() - return text + with open(os.path.join(os.path.dirname(__file__), *rnames)) as f: + return f.read() + +ZCML_REQUIRES = [ + 'zope.configuration', +] + +COMPONENT_REQUIRES = [ + 'zope.component >= 4.0.1', +] + +TESTS_REQUIRE = ZCML_REQUIRES + COMPONENT_REQUIRES + [ + 'zope.copy >= 4.0', + 'zope.testrunner', +] + +DOCS_REQUIRE = [ + 'Sphinx', + 'repoze.sphinx.autointerface', +] + ZCML_REQUIRES + COMPONENT_REQUIRES # doctest snippets need these setup(name='zope.location', version='4.1.0.dev0', @@ -34,10 +52,10 @@ setup(name='zope.location', read('README.rst') + '\n\n' + read('CHANGES.rst') - ), + ), license='ZPL 2.1', keywords=('zope location structural'), - classifiers = [ + classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Intended Audience :: Developers', @@ -46,43 +64,33 @@ setup(name='zope.location', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Natural Language :: English', 'Operating System :: OS Independent', 'Topic :: Internet :: WWW/HTTP', - 'Framework :: Zope3'], - url='http://pypi.python.org/pypi/zope.location/', + 'Framework :: Zope3', + ], + url='http://github.com/zopefoundation/zope.location/', packages=find_packages('src'), - package_dir = {'': 'src'}, + package_dir={'': 'src'}, namespace_packages=['zope',], - install_requires=['setuptools', - 'zope.interface>=4.0.2', - 'zope.schema>=4.2.2', - 'zope.proxy>=4.0.1', - ], + install_requires=[ + 'setuptools', + 'zope.interface>=4.0.2', + 'zope.schema>=4.2.2', + 'zope.proxy>=4.0.1', + ], extras_require={ - 'zcml': ['zope.configuration'], - 'component': ['zope.component>=4.0.1'], - 'testing': [ - 'nose', - 'coverage', - 'zope.configuration>=4.0', - 'zope.copy>=4.0', - ], - 'docs': [ - 'Sphinx', - 'repoze.sphinx.autointerface', - # doctest snippets rely on these: - 'zope.component>=4.0.1', - 'zope.configuration', - 'zope.copy', - ], + 'zcml': ZCML_REQUIRES, + 'component': COMPONENT_REQUIRES, + 'test': TESTS_REQUIRE, + 'docs': DOCS_REQUIRE, }, test_suite='zope.location.tests', - include_package_data = True, - zip_safe = False, + include_package_data=True, + zip_safe=False, ) diff --git a/src/zope/__init__.py b/src/zope/__init__.py index de40ea7..2cdb0e4 100644 --- a/src/zope/__init__.py +++ b/src/zope/__init__.py @@ -1 +1 @@ -__import__('pkg_resources').declare_namespace(__name__) +__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover diff --git a/src/zope/location/_compat.py b/src/zope/location/_compat.py deleted file mode 100644 index bcbc050..0000000 --- a/src/zope/location/_compat.py +++ /dev/null @@ -1,24 +0,0 @@ -############################################################################## -# -# Copyright (c) 2003-2009 Zope Foundation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## - -import sys - -PY3 = sys.version_info[0] >= 3 - -if PY3: #pragma NO COVER - def u(s): - return s -else: #pragma NO COVER - def u(s): - return unicode(s, "unicode_escape") diff --git a/src/zope/location/interfaces.py b/src/zope/location/interfaces.py index 153d0b1..b490a09 100644 --- a/src/zope/location/interfaces.py +++ b/src/zope/location/interfaces.py @@ -19,7 +19,6 @@ from zope.interface import Interface from zope.interface import Attribute from zope.schema import TextLine -from zope.location._compat import u class ILocation(Interface): """Objects that can be located in a hierachy. @@ -42,9 +41,9 @@ class ILocation(Interface): __parent__ = Attribute("The parent in the location hierarchy.") __name__ = TextLine( - title=u("The name within the parent"), - description=u("The object can be looked up from the parent's " - "sublocations using this name."), + title=(u"The name within the parent"), + description=(u"The object can be looked up from the parent's " + u"sublocations using this name."), required=False, default=None) @@ -128,6 +127,6 @@ class LocationError(KeyError, LookupError): # backward-compatibility try: from zope.component.interfaces import ISite -except ImportError: #pragma NO COVER +except ImportError: # pragma: no cover class ISite(Interface): pass diff --git a/src/zope/location/pickling.py b/src/zope/location/pickling.py index 17343f4..46e6217 100644 --- a/src/zope/location/pickling.py +++ b/src/zope/location/pickling.py @@ -20,9 +20,9 @@ from zope.location.location import inside try: from zope.copy.interfaces import ICopyHook, ResumeCopy -except ImportError: #pragma NO COVER +except ImportError: # pragma: no cover raise NotImplementedError("zope.location.pickling is not supported " - "because zope.copy is not available") + "because zope.copy is not available") @implementer(ICopyHook) @@ -32,7 +32,7 @@ class LocationCopyHook(object): """ def __init__(self, context): self.context = context - + def __call__(self, toplevel, register): if not inside(self.context, toplevel): return self.context diff --git a/src/zope/location/tests/test_configure.py b/src/zope/location/tests/test_configure.py index 83343b7..ec31efb 100644 --- a/src/zope/location/tests/test_configure.py +++ b/src/zope/location/tests/test_configure.py @@ -18,29 +18,20 @@ import unittest class Test_ZCML_loads(unittest.TestCase): def test_it(self): - try: - import zope.component # no registrations made if not present - except ImportError: - ADAPTERS_REGISTERED = 0 - else: - ADAPTERS_REGISTERED = 4 - try: - from zope.configuration.xmlconfig import _clearContext - from zope.configuration.xmlconfig import _getContext - from zope.configuration.xmlconfig import XMLConfig - except ImportError: - pass - else: - import zope.location - _clearContext() - context = _getContext() - XMLConfig('configure.zcml', zope.location) - adapters = ([x for x in context.actions - if x['discriminator'] is not None]) - self.assertEqual(len(adapters), ADAPTERS_REGISTERED) - + import zope.component # no registrations made if not present + ADAPTERS_REGISTERED = 4 + from zope.configuration.xmlconfig import _clearContext + from zope.configuration.xmlconfig import _getContext + from zope.configuration.xmlconfig import XMLConfig + import zope.location + + _clearContext() + context = _getContext() + XMLConfig('configure.zcml', zope.location) + adapters = ([x for x in context.actions + if x['discriminator'] is not None]) + self.assertEqual(len(adapters), ADAPTERS_REGISTERED) + def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(Test_ZCML_loads), - )) + return unittest.defaultTestLoader.loadTestsFromName(__name__) diff --git a/src/zope/location/tests/test_location.py b/src/zope/location/tests/test_location.py index 552af75..ea60099 100644 --- a/src/zope/location/tests/test_location.py +++ b/src/zope/location/tests/test_location.py @@ -244,11 +244,9 @@ class LocationProxyTests(unittest.TestCase, ConformsToILocation): if obj is None: obj = object() if container is _MARKER: - if name is _MARKER: - return self._getTargetClass()(obj) - return self._getTargetClass()(obj, name=name) - if name is _MARKER: - return self._getTargetClass()(obj, container) + self.assertIs(name, _MARKER) + return self._getTargetClass()(obj) + self.assertIsNot(name, _MARKER) return self._getTargetClass()(obj, container, name) def test_ctor_defaults(self): @@ -287,8 +285,6 @@ class LocationProxyTests(unittest.TestCase, ConformsToILocation): def test___doc___from_target_class(self): klass = self._getTargetClass() - class Derived(klass): - """DERIVED""" class Context(object): """CONTEXT""" proxy = self._makeOne(Context()) @@ -296,8 +292,6 @@ class LocationProxyTests(unittest.TestCase, ConformsToILocation): def test___doc___from_target_instance(self): klass = self._getTargetClass() - class Derived(klass): - """DERIVED""" class Context(object): """CONTEXT""" context = Context() @@ -317,7 +311,7 @@ class LocationProxyTests(unittest.TestCase, ConformsToILocation): import pickle class Context(object): def __reduce__(self): - return {'a': 1} + raise AssertionError("This is not called") proxy = self._makeOne(Context()) # XXX: this TypeError is not due to LocationProxy.__reduce__: # it's descriptor (under pure Python) isn't begin triggered @@ -374,7 +368,7 @@ class LocationPyProxyTests(LocationProxyTests): 'zope.proxy.decorator'): try: del sys.modules[mod] - except KeyError: + except KeyError: # pragma: no cover pass import zope.proxy self.orig = (zope.proxy.ProxyBase, @@ -411,14 +405,4 @@ class LocationPyProxyTests(LocationProxyTests): def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(LocationTests), - unittest.makeSuite(Test_locate), - unittest.makeSuite(Test_located), - unittest.makeSuite(Test_inside), - unittest.makeSuite(Test_LocationIterator), - unittest.makeSuite(ClassAndInstanceDescrTests), - # In case of Python-only version, tests are simply run twice. - unittest.makeSuite(LocationProxyTests), - unittest.makeSuite(LocationPyProxyTests), - )) + return unittest.defaultTestLoader.loadTestsFromName(__name__) diff --git a/src/zope/location/tests/test_pickling.py b/src/zope/location/tests/test_pickling.py index 5b3c4e9..063c9f6 100644 --- a/src/zope/location/tests/test_pickling.py +++ b/src/zope/location/tests/test_pickling.py @@ -13,54 +13,49 @@ ############################################################################## import unittest -try: - import zope.copy -except ImportError: - def test_suite(): - return unittest.TestSuite() -else: - class LocationCopyHookTests(unittest.TestCase): - def _getTargetClass(self): - from zope.location.pickling import LocationCopyHook - return LocationCopyHook +import zope.copy - def _makeOne(self, obj=None): - if obj is None: - obj = object() - return self._getTargetClass()(obj) +class LocationCopyHookTests(unittest.TestCase): - def test_class_conforms_to_ICopyHook(self): - from zope.interface.verify import verifyClass - from zope.copy.interfaces import ICopyHook - verifyClass(ICopyHook, self._getTargetClass()) + def _getTargetClass(self): + from zope.location.pickling import LocationCopyHook + return LocationCopyHook - def test_instance_conforms_to_ICopyHook(self): - from zope.interface.verify import verifyObject - from zope.copy.interfaces import ICopyHook - verifyObject(ICopyHook, self._makeOne()) + def _makeOne(self, obj=None): + if obj is None: + obj = object() + return self._getTargetClass()(obj) - def test___call___w_context_inside_toplevel(self): - from zope.copy.interfaces import ResumeCopy - class Dummy(object): - __parent__ = __name__ = None - top_level = Dummy() - context = Dummy() - context.__parent__ = top_level - hook = self._makeOne(context) - self.assertRaises(ResumeCopy, hook, top_level, object()) + def test_class_conforms_to_ICopyHook(self): + from zope.interface.verify import verifyClass + from zope.copy.interfaces import ICopyHook + verifyClass(ICopyHook, self._getTargetClass()) - def test___call___w_context_outside_toplevel(self): - class Dummy(object): - __parent__ = __name__ = None - top_level = Dummy() - context = Dummy() - hook = self._makeOne(context) - self.assertTrue(hook(top_level, object()) is context) + def test_instance_conforms_to_ICopyHook(self): + from zope.interface.verify import verifyObject + from zope.copy.interfaces import ICopyHook + verifyObject(ICopyHook, self._makeOne()) + def test___call___w_context_inside_toplevel(self): + from zope.copy.interfaces import ResumeCopy + class Dummy(object): + __parent__ = __name__ = None + top_level = Dummy() + context = Dummy() + context.__parent__ = top_level + hook = self._makeOne(context) + self.assertRaises(ResumeCopy, hook, top_level, object()) + def test___call___w_context_outside_toplevel(self): + class Dummy(object): + __parent__ = __name__ = None + top_level = Dummy() + context = Dummy() + hook = self._makeOne(context) + self.assertTrue(hook(top_level, object()) is context) - def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(LocationCopyHookTests), - )) + + +def test_suite(): + return unittest.defaultTestLoader.loadTestsFromName(__name__) diff --git a/src/zope/location/traversing.py b/src/zope/location/traversing.py index 86a926e..2e6836c 100644 --- a/src/zope/location/traversing.py +++ b/src/zope/location/traversing.py @@ -20,7 +20,6 @@ from zope.interface import implementer from zope.location.interfaces import ILocationInfo from zope.location.interfaces import IRoot from zope.location.interfaces import ISite # zope.component, if present -from zope.location._compat import u @implementer(ILocationInfo) @@ -57,9 +56,8 @@ class LocationPhysicallyLocatable(object): if path: path.append('') path.reverse() - return u('/').join(path) - else: - return u('/') + return u'/'.join(path) + return u'/' path.append(context.__name__) context = context.__parent__ max -= 1 @@ -115,7 +113,7 @@ class LocationPhysicallyLocatable(object): @implementer(ILocationInfo) class RootPhysicallyLocatable(object): """Provide location information for the root object - + This adapter is very simple, because there's no places to search for parents and nearest sites, so we are only working with context object, knowing that its the root object already. @@ -131,7 +129,7 @@ class RootPhysicallyLocatable(object): def getPath(self): """See ILocationInfo """ - return u('/') + return u'/' def getParent(self): """See ILocationInfo. @@ -146,7 +144,7 @@ class RootPhysicallyLocatable(object): def getName(self): """See ILocationInfo """ - return u('') + return u'' def getNearestSite(self): """See ILocationInfo @@ -3,48 +3,31 @@ envlist = # Jython support pending 2.7 support, due 2012-07-15 or so. See: # http://fwierzbicki.blogspot.com/2012/03/adconion-to-fund-jython-27.html # py27,jython,pypy,coverage - py27,py33,py34,py35,pypy,pypy3,coverage,docs + py27,py34,py35,py36,pypy,pypy3,coverage [testenv] commands = - python setup.py test -q + zope-testrunner --test-path=src [] + sphinx-build -b doctest -d {envdir}/.cache/doctrees docs {envdir}/.cache/doctest deps = - zope.configuration - zope.copy - zope.interface - zope.proxy - zope.schema + .[test,docs] [testenv:jython] commands = jython setup.py test -q -deps = - zope.configuration - zope.copy - zope.interface - zope.proxy - zope.schema [testenv:coverage] +usedevelop = true basepython = python2.7 commands = -# The installed version messes up nose's test discovery / coverage reporting -# So, we uninstall that from the environment, and then install the editable -# version, before running nosetests. - pip uninstall -y zope.location - pip install -e . - nosetests --with-xunit --with-xcoverage + coverage run -m zope.testrunner --test-path=src + coverage run -a -m sphinx -b doctest -d {envdir}/.cache/doctrees docs {envdir}/.cache/doctest + coverage report deps = - zope.configuration - zope.copy - zope.interface - zope.proxy - zope.schema - zope.component - nose + {[testenv]deps} coverage - nosexcover + [testenv:docs] basepython = @@ -53,11 +36,4 @@ commands = sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html sphinx-build -b doctest -d docs/_build/doctrees docs docs/_build/doctest deps = - zope.configuration - zope.copy - zope.interface - zope.proxy - zope.schema - zope.component - Sphinx - repoze.sphinx.autointerface + .[docs] |