Skip to content

Commit

Permalink
Improve coverage. Some things, like find, are completely untested.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Apr 22, 2017
1 parent f59dfce commit 3d8a6ed
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 112 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ build/
dist/
*.egg-info/
.tox/
.coverage
htmlcov/
7 changes: 1 addition & 6 deletions src/zope/__init__.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 1 addition & 6 deletions src/zope/app/__init__.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/zope/app/container/browser/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions src/zope/app/container/browser/tests/test_adding.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ class Factory(object):
title = ''
description = ''

def getInterfaces(self):
return ()

def __call__(self):
return Content()

Expand Down Expand Up @@ -597,5 +594,5 @@ def test_suite():
checker=checker),
))

if __name__=='__main__':
if __name__=='__main__': # pragma: no cover
unittest.main(defaultTest='test_suite')
4 changes: 2 additions & 2 deletions src/zope/app/container/browser/tests/test_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__


Expand Down Expand Up @@ -378,5 +378,5 @@ def test_suite():
makeSuite(TestCutCopyPaste),
))

if __name__=='__main__':
if __name__=='__main__': # pragma: no cover
main(defaultTest='test_suite')
14 changes: 10 additions & 4 deletions src/zope/app/container/browser/tests/test_contents_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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'),
Expand Down Expand Up @@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -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')
2 changes: 1 addition & 1 deletion src/zope/app/container/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""

# BBB
from zope.container.dependency import (
from zope.app.dependable.dependency import (
exception_msg,
CheckDependency
)
67 changes: 3 additions & 64 deletions src/zope/app/container/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
23 changes: 0 additions & 23 deletions src/zope/app/container/tests/placelesssetup.py

This file was deleted.

49 changes: 49 additions & 0 deletions src/zope/app/container/tests/test_bwc_imports.py
Original file line number Diff line number Diff line change
@@ -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__)

0 comments on commit 3d8a6ed

Please sign in to comment.