Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Really hit 100% coverage through additional tests, including of confi…
Browse files Browse the repository at this point in the history
…gure.zcml
  • Loading branch information
jamadden committed Apr 22, 2017
1 parent 962fd49 commit e6fa4fa
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -9,3 +9,5 @@ build/
dist/
*.egg-info/
.tox/
.coverage
htmlcov/
12 changes: 9 additions & 3 deletions setup.py
Expand Up @@ -26,6 +26,11 @@ def read(*rnames):
return f.read()

version = '4.0.0.dev0'
tests_require = [
'zope.container',
'zope.testing',
'zope.testrunner',
]

setup(name='zope.app.dependable',
version=version,
Expand Down Expand Up @@ -61,9 +66,10 @@ def read(*rnames):
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope', 'zope.app'],
extras_require=dict(test=[
'zope.testrunner',
]),
extras_require={
'test': tests_require,
},
tests_require=tests_require,
install_requires=[
'setuptools',
'zope.annotation',
Expand Down
7 changes: 6 additions & 1 deletion src/zope/app/dependable/__init__.py
Expand Up @@ -37,6 +37,7 @@ def __init__(self, context):
parent = getParent(self.context)
except TypeError:
parent = None

if parent is not None:
try:
pp = getPath(parent)
Expand Down Expand Up @@ -84,7 +85,11 @@ def _make_relative(self, path):
path = canonicalPath(path)
if path.startswith(self.pp):
path = path[self.pplen:]
while path.startswith("/"):
while path.startswith("/"): # pragma: no cover
# We should not be able to get here. canonicalPath
# doesn't allow trailing / in a path segment, and we
# already cut off the whole length of the parent, which
# we guaranteed to begin and end with a /
path = path[1:]
return path

Expand Down
2 changes: 2 additions & 0 deletions src/zope/app/dependable/configure.zcml
Expand Up @@ -3,6 +3,8 @@
xmlns:zcml="http://namespaces.zope.org/zcml"
>

<include package="zope.component" file="meta.zcml" />

<adapter
factory="zope.app.dependable.Dependable"
provides="zope.app.dependable.interfaces.IDependable"
Expand Down
54 changes: 50 additions & 4 deletions src/zope/app/dependable/tests.py
Expand Up @@ -18,9 +18,14 @@

from zope.annotation.attribute import AttributeAnnotations
from zope.location.interfaces import ILocationInfo
from zope.interface import implementer, verify
from zope.interface import implementer, verify, directlyProvides
from zope.lifecycleevent import ObjectRemovedEvent

from zope.location.interfaces import ILocationInfo

from zope.testing.cleanup import CleanUp

import zope.app.dependable
from zope.app.dependable.dependency import CheckDependency
from zope.app.dependable.interfaces import IDependable, DependencyError

Expand All @@ -39,11 +44,11 @@ def getPath(self):
return '/dummy-object'


class Test(unittest.TestCase):
class TestDependable(unittest.TestCase):

def factory(self):
def factory(self, obj=None):
from zope.app.dependable import Dependable
return Dependable(AttributeAnnotations(C()))
return Dependable(obj if obj is not None else AttributeAnnotations(C()))

def testVerifyInterface(self):
object = self.factory()
Expand Down Expand Up @@ -88,6 +93,47 @@ def testCheckDependency(self):
event = ObjectRemovedEvent(obj, parent, 'oldName')
self.assertRaises(DependencyError, CheckDependency, event)

def testWithParent(self):
grandparent = C()
grandparent.__name__ = 'root'

parent = C()
parent.__name__ = 'parent'
parent.__parent__ = grandparent

obj = AttributeAnnotations(C())
obj.__parent__ = parent
obj.__name__ = 'obj'

from zope.traversing.api import getPath

# If we can't get the parent path, it's just /
dependable = self.factory(obj)
self.assertEqual('/', dependable.pp)

# If we can, it's whatever it reported, always with a
# trailing /
directlyProvides(parent, ILocationInfo)
parent.getPath = lambda: '/root/parent'
dependable = self.factory(obj)
self.assertEqual('/root/parent/', dependable.pp)

parent.getPath = lambda: '/root/parent/'
dependable = self.factory(obj)
self.assertEqual('/root/parent/', dependable.pp)


dependable.addDependent('/root/parent/sibling/nephew')
dependents = list(dependable.dependents())
self.assertEqual(dependents, ['/root/parent/sibling/nephew'])


class TestConfiguration(CleanUp, unittest.TestCase):

def test_configuration(self):
from zope.configuration import xmlconfig
xmlconfig.file('configure.zcml', package=zope.app.dependable)


def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
Expand Down

0 comments on commit e6fa4fa

Please sign in to comment.