diff --git a/.gitignore b/.gitignore index 5149542..6bacfe5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ build/ dist/ *.egg-info/ .tox/ +.coverage +htmlcov/ diff --git a/src/zope/__init__.py b/src/zope/__init__.py index 2e2033b..155a31d 100644 --- a/src/zope/__init__.py +++ b/src/zope/__init__.py @@ -1,7 +1,2 @@ # this is a namespace package -try: - import pkg_resources - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - __path__ = pkgutil.extend_path(__path__, __name__) +__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover diff --git a/src/zope/app/__init__.py b/src/zope/app/__init__.py index 2e2033b..155a31d 100644 --- a/src/zope/app/__init__.py +++ b/src/zope/app/__init__.py @@ -1,7 +1,2 @@ # this is a namespace package -try: - import pkg_resources - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - __path__ = pkgutil.extend_path(__path__, __name__) +__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover diff --git a/src/zope/app/container/browser/tests/__init__.py b/src/zope/app/container/browser/tests/__init__.py index 52b67f4..5ccc28b 100644 --- a/src/zope/app/container/browser/tests/__init__.py +++ b/src/zope/app/container/browser/tests/__init__.py @@ -55,7 +55,8 @@ def publish(self, path, basic=None, form=None): self._testapp.authorization = None env = {'wsgi.handleErrors': False} if form: - response = self._testapp.post(path, params=form, extra_environ=env) + response = self._testapp.post(path, params=form, extra_environ=env, + content_type="application/x-www-form-urlencoded; charset=utf-8") else: response = self._testapp.get(path, extra_environ=env) return response diff --git a/src/zope/app/container/browser/tests/test_adding.py b/src/zope/app/container/browser/tests/test_adding.py index 9f2d843..e2f74ee 100644 --- a/src/zope/app/container/browser/tests/test_adding.py +++ b/src/zope/app/container/browser/tests/test_adding.py @@ -70,9 +70,6 @@ class Factory(object): title = '' description = '' - def getInterfaces(self): - return () - def __call__(self): return Content() @@ -597,5 +594,5 @@ def test_suite(): checker=checker), )) -if __name__=='__main__': +if __name__=='__main__': # pragma: no cover unittest.main(defaultTest='test_suite') diff --git a/src/zope/app/container/browser/tests/test_contents.py b/src/zope/app/container/browser/tests/test_contents.py index 4d877b6..3b30c8c 100644 --- a/src/zope/app/container/browser/tests/test_contents.py +++ b/src/zope/app/container/browser/tests/test_contents.py @@ -225,7 +225,7 @@ def __new__(class_, context): return annotations def __init__(self, context): pass - def __repr__(self): + def __repr__(self): # pragma: no cover return "<%s.PrincipalAnnotations object>" % __name__ @@ -378,5 +378,5 @@ def test_suite(): makeSuite(TestCutCopyPaste), )) -if __name__=='__main__': +if __name__=='__main__': # pragma: no cover main(defaultTest='test_suite') diff --git a/src/zope/app/container/browser/tests/test_contents_functional.py b/src/zope/app/container/browser/tests/test_contents_functional.py index 17af1ac..9203e02 100644 --- a/src/zope/app/container/browser/tests/test_contents_functional.py +++ b/src/zope/app/container/browser/tests/test_contents_functional.py @@ -104,6 +104,7 @@ def test_inplace_add(self): root._p_jar.sync() self.assertIn('foo', root) + def test_inplace_rename_multiple(self): root = self.getRootFolder() root['foo'] = File() @@ -319,9 +320,14 @@ def test_unmoveable_object(self): body = response.text self.assertIn("cannot be moved", body) - @unittest.skip("Fails under webtest; encoding of the param isn't right") + @unittest.skipIf(str is not bytes, #Py2 only + "Only Python 2 can do str(b'encoded') and get the right thing") def test_copy_then_delete_with_unicode_name(self): - """Tests unicode on object copied then deleted (#238579).""" + # Tests unicode on object copied then deleted (#238579) + # The zope.publisher.browser conversion methods for text/str + # rely on the default encoding, which breaks on this unicode name in Python 3. + # We either wind up with "b'voil\\xe0'" or a list of the ints that make + # up the bytes, depending on which order we try for the type names. # create a file with an accentuated unicode name root = self.getRootFolder() @@ -330,7 +336,7 @@ def test_copy_then_delete_with_unicode_name(self): # copy the object response = self.publish('/@@contents.html', basic='mgr:mgrpw', form={ - 'ids' : (u'voil\xe0',), + 'ids:list' : (u'voil\xe0'.encode('utf-8'),), 'container_copy_button' : '' }) self.assertEqual(response.status_int, 302) self.assertEqual(response.headers.get('Location'), @@ -362,5 +368,5 @@ def _http(query_str, *args, **kwargs): suite.addTest(index) return suite -if __name__=='__main__': +if __name__=='__main__': # pragma: no cover unittest.main(defaultTest='test_suite') diff --git a/src/zope/app/container/browser/tests/test_view_permissions.py b/src/zope/app/container/browser/tests/test_view_permissions.py index cefb299..29b65b7 100644 --- a/src/zope/app/container/browser/tests/test_view_permissions.py +++ b/src/zope/app/container/browser/tests/test_view_permissions.py @@ -102,5 +102,5 @@ def test_suite(): suite.addTest(unittest.makeSuite(Tests)) return suite -if __name__=='__main__': +if __name__=='__main__': # pragma: no cover unittest.main(defaultTest='test_suite') diff --git a/src/zope/app/container/dependency.py b/src/zope/app/container/dependency.py index dbdcc84..f30309e 100644 --- a/src/zope/app/container/dependency.py +++ b/src/zope/app/container/dependency.py @@ -16,7 +16,7 @@ """ # BBB -from zope.container.dependency import ( +from zope.app.dependable.dependency import ( exception_msg, CheckDependency ) diff --git a/src/zope/app/container/testing.py b/src/zope/app/container/testing.py index 237e470..b314572 100644 --- a/src/zope/app/container/testing.py +++ b/src/zope/app/container/testing.py @@ -4,12 +4,10 @@ try: from zope.testing.cleanup import tearDown as tTearDown -except ImportError: +except ImportError: # pragma: no cover def tTearDown(): pass -from zope.traversing.api import traverse - from zope.app.wsgi.testlayer import BrowserLayer import zope.app.container @@ -68,62 +66,12 @@ def setUpTraversal(): (ISimpleReadContainer,), ITraversable) -class Place(object): - - def __init__(self, path): - self.path = path - - def __get__(self, inst, cls=None): - if inst is None: - return self - - try: - # Use __dict__ directly to avoid infinite recursion - root = inst.__dict__['rootFolder'] - except KeyError: - root = inst.rootFolder = buildSampleFolderTree() - - return traverse(root, self.path) - - class PlacefulSetup(PlacelessSetup): - # Places :) - rootFolder = Place(u'') - - folder1 = Place(u'folder1') - folder1_1 = Place(u'folder1/folder1_1') - folder1_1_1 = Place(u'folder1/folder1_1/folder1_1_1') - folder1_1_2 = Place(u'folder1/folder1_2/folder1_1_2') - folder1_2 = Place(u'folder1/folder1_2') - folder1_2_1 = Place(u'folder1/folder1_2/folder1_2_1') - - folder2 = Place(u'folder2') - folder2_1 = Place(u'folder2/folder2_1') - folder2_1_1 = Place(u'folder2/folder2_1/folder2_1_1') - - folder3 = Place(u"\N{CYRILLIC SMALL LETTER PE}" - u"\N{CYRILLIC SMALL LETTER A}" - u"\N{CYRILLIC SMALL LETTER PE}" - u"\N{CYRILLIC SMALL LETTER KA}" - u"\N{CYRILLIC SMALL LETTER A}3") - folder3_1 = Place(u"\N{CYRILLIC SMALL LETTER PE}" - u"\N{CYRILLIC SMALL LETTER A}" - u"\N{CYRILLIC SMALL LETTER PE}" - u"\N{CYRILLIC SMALL LETTER KA}" - u"\N{CYRILLIC SMALL LETTER A}3/" - u"\N{CYRILLIC SMALL LETTER PE}" - u"\N{CYRILLIC SMALL LETTER A}" - u"\N{CYRILLIC SMALL LETTER PE}" - u"\N{CYRILLIC SMALL LETTER KA}" - u"\N{CYRILLIC SMALL LETTER A}3_1") - - def setUp(self, folders=False, site=False): + def setUp(self): super(PlacefulSetup, self).setUp() cSetUp() setUpTraversal() - if folders or site: - return self.buildFolders(site) from zope.security.management import newInteraction newInteraction() @@ -133,14 +81,5 @@ def tearDown(self): cTearDown() tTearDown() - def buildFolders(self, site=False): + def buildFolders(self): self.rootFolder = buildSampleFolderTree() - if site: - return self.makeSite() - - def makeSite(self, path='/'): - folder = traverse(self.rootFolder, path) - return setup.createSiteManager(folder, True) - - def createRootFolder(self): - self.rootFolder = zope.site.folder.rootFolder() diff --git a/src/zope/app/container/tests/placelesssetup.py b/src/zope/app/container/tests/placelesssetup.py deleted file mode 100644 index a636d1d..0000000 --- a/src/zope/app/container/tests/placelesssetup.py +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################## -# -# Copyright (c) 2002 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. -# -############################################################################## -"""Unit test logic for setting up and tearing down basic infrastructure -""" -from zope.app.testing import ztapi -from zope.app.container.interfaces import IWriteContainer, INameChooser -from zope.app.container.contained import NameChooser - -class PlacelessSetup(object): - - def setUp(self): - ztapi.provideAdapter(IWriteContainer, INameChooser, NameChooser) diff --git a/src/zope/app/container/tests/test_bwc_imports.py b/src/zope/app/container/tests/test_bwc_imports.py new file mode 100644 index 0000000..95d8292 --- /dev/null +++ b/src/zope/app/container/tests/test_bwc_imports.py @@ -0,0 +1,49 @@ +############################################################################## +# +# Copyright (c) 2017 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 unittest + +class TestImports(unittest.TestCase): + + def test_traversal_import(self): + import zope.app.container.traversal as m + self.assertIn('ContainerTraverser', m.__dict__) + + def test_size_import(self): + import zope.app.container.size as m + self.assertIn('ContainerSized', m.__dict__) + + def test_ordered_import(self): + import zope.app.container.ordered as m + self.assertIn('OrderedContainer', m.__dict__) + + def test_btree_import(self): + import zope.app.container.btree as m + self.assertIn('BTreeContainer', m.__dict__) + + def test_container_import(self): + import zope.app.container.dependency as m + self.assertIn('CheckDependency', m.__dict__) + + def test_directory_import(self): + import zope.app.container.directory as m + self.assertIn('Cloner', m.__dict__) + + def test_find_import(self): + import zope.app.container.find as m + self.assertIn('FindAdapter', m.__dict__) + + +def test_suite(): + return unittest.defaultTestLoader.loadTestsFromName(__name__)