Skip to content

Commit

Permalink
100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jun 30, 2017
1 parent 43d7351 commit 304af7a
Show file tree
Hide file tree
Showing 22 changed files with 182 additions and 352 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ exclude_lines =
pragma NO COVER
if __name__ == '__main__':
raise NotImplementedError
self.fail
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ coverage.xml
.coverage
dist/
.eggs/
htmlcov/
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: false
matrix:
include:
- python: 2.7
env: MINIMAL="-t !persistentregistry -t !security"
env: MINIMAL=1
python:
- 2.7
- 3.4
Expand All @@ -12,7 +12,7 @@ python:
- pypy-5.6.0

script:
- coverage run -m zope.testrunner --test-path=src $MINIMAL
- coverage run -m zope.testrunner --test-path=src
- if [[ -z "$MINIMAL" ]]; then sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html; fi
- if [[ -z "$MINIMAL" ]]; then coverage run -a `which sphinx-build` -b doctest -d docs/_build/doctrees docs docs/_build/doctest; fi

Expand Down
11 changes: 8 additions & 3 deletions docs/testlayer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,29 @@ ZCMLLayer

We now want a layer that loads up some ZCML from a file. The default
is ``ftesting.zcml``, but here we'll load a test ``testlayer.zcml``.
We can also choose to provide extra ZCML features (here, "devmode").

.. doctest::

>>> from zope.component.testlayer import ZCMLFileLayer
>>> import zope.component.testfiles
>>> zcml_file_layer = ZCMLFileLayer(
... zope.component.testfiles,
... 'testlayer.zcml')
... 'testlayer.zcml',
... features=["devmode"])

>>> class TestCase(unittest.TestCase):
... layer = zcml_file_layer
...
... def testFoo(self):
... # The feature was registered
... self.assertTrue(self.layer.context.hasFeature('devmode'))
... # we should now have the adapter registered
... from zope import component
... from zope.component.testfiles import components
... self.assert_(isinstance(
... components.IApp2(components.content), components.Comp2))
... self.assertIsInstance(
... components.IApp2(components.content), components.Comp2)


Since the ZCML sets up an adapter, we expect the tests to pass:

Expand Down
9 changes: 5 additions & 4 deletions src/zope/component/standalonetests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
See: https://bugs.launchpad.net/zope3/+bug/98401
"""
import sys
import pickle

def write(x): # pragma: NO COVER
import sys # pragma: no cover (runs in subprocess)
import pickle # pragma: no cover (runs in subprocess)

def write(x): # pragma: no cover (runs in subprocess)
sys.stdout.write('%s\n' % x)

if __name__ == "__main__": #pragma NO COVER (runs in subprocess)
if __name__ == "__main__": # pragma: no cover (runs in subprocess)
if sys.version_info[0] >= 3:
# TextIO? Are you kidding me?
data = sys.stdin.buffer.read()
Expand Down
3 changes: 1 addition & 2 deletions src/zope/component/testfiles/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def __init__(self, context):
self.context = context

class Comp3(object):
def __init__(self, context):
self.context = context
pass

@adapter(IContent)
@implementer(IApp)
Expand Down
48 changes: 1 addition & 47 deletions src/zope/component/testfiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,6 @@
"""

from zope.interface import Interface
from zope.interface import implementer
from zope.interface import directlyProvides

class Request(object):

def __init__(self, type):
directlyProvides(self, type)

class IR(Interface):
pass

class IV(Interface):
def index():
pass

class IC(Interface): pass

@implementer(IV)
class V1(object):

def __init__(self, context, request):
self.context = context
self.request = request

def index(self):
return 'V1 here'

def action(self):
return 'done'

class VZMI(V1):
def index(self):
return 'ZMI here'

@implementer(IV)
class R1(object):

def index(self):
return 'R1 here'

def action(self):
return 'R done'

def __init__(self, request):
pass


class RZMI(R1):
class IC(Interface):
pass
18 changes: 9 additions & 9 deletions src/zope/component/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
import zope.component.event

# we really don't need special setup now:
class _PlacelessSetupFallback(object):
def cleanUp(self):
from zope.component.globalregistry import base
base.__init__('base')

setUp = tearDown = cleanUp

try:
from zope.testing.cleanup import CleanUp as PlacelessSetup
except ImportError:
class PlacelessSetup(object):
def cleanUp(self):
from zope.component.globalregistry import base
base.__init__('base')
def setUp(self):
self.cleanUp()
def tearDown(self):
self.cleanUp()
except ImportError: # pragma: no cover
PlacelessSetup = _PlacelessSetupFallback

def setUp(test=None):
PlacelessSetup().setUp()
Expand Down
4 changes: 2 additions & 2 deletions src/zope/component/testlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from zope.configuration import xmlconfig, config
try:
from zope.testing.cleanup import cleanUp
except ImportError:
except ImportError: # pragma: no cover
def cleanUp():
pass

Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(self, package, name=None):
self.__name__ = name
self.__module__ = package.__name__
self.package = package

def setUp(self):
pass

Expand Down
9 changes: 8 additions & 1 deletion src/zope/component/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# tests package
import unittest

def skipIfNoSecurity(testfunc):
try:
import zope.security
except ImportError:
return unittest.skip("zope.security not installed")(testfunc)
return testfunc
5 changes: 2 additions & 3 deletions src/zope/component/tests/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ISII(Interface):
pass

def noop(*args):
pass
pass # pragma: no cover

class U(object):

Expand Down Expand Up @@ -123,8 +123,7 @@ def __init__(self, context):

@implementer(I3)
class Comp2(object):
def __init__(self, context):
self.context = context
pass


class ConformsToIComponentLookup(object):
Expand Down
48 changes: 7 additions & 41 deletions src/zope/component/tests/test__api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ class IBar(Interface):
pass
@implementer(IFoo)
class Global(object):
def __init__(self, context):
self.context = context
pass
@implementer(IFoo)
class Local(object):
def __init__(self, context):
Expand All @@ -114,10 +113,6 @@ class Test_queryAdapterInContext(unittest.TestCase):

from zope.component.testing import setUp, tearDown

def _callFUT(self, *args, **kw):
from zope.component import queryAdapterInContext
return queryAdapterInContext(*args, **kw)

def test_miss(self):
from zope.interface import Interface
from zope.component import queryAdapterInContext
Expand All @@ -136,7 +131,7 @@ class Foo(object):
def __conform__(self, iface, default=None):
if iface is IFoo:
return _adapted
return default
raise NotImplementedError()
self.assertTrue(
queryAdapterInContext(Foo(), IFoo, context=None) is _adapted)

Expand All @@ -148,9 +143,7 @@ class IFoo(Interface):
_adapted = object()
class Foo(object):
def __conform__(self, iface, default=None):
if iface is IFoo:
return _adapted
return default
raise NotImplementedError()
# call via class, triggering TypeError
self.assertEqual(queryAdapterInContext(Foo, IFoo, context=None), None)

Expand Down Expand Up @@ -338,8 +331,7 @@ class IBar(Interface):
pass
@implementer(IFoo)
class Global(object):
def __init__(self, context):
self.context = context
pass
@implementer(IFoo)
class Local(object):
def __init__(self, context):
Expand Down Expand Up @@ -570,8 +562,7 @@ class Baz(object):
pass
@implementer(IFoo)
class Global(object):
def __init__(self, first, second):
self.first, self.second = first, second
pass
@implementer(IFoo)
class Local(object):
def __init__(self, first, second):
Expand Down Expand Up @@ -1060,7 +1051,7 @@ def __conform__(self, iface):
def queryUtility(self, iface, name, default):
if iface is IFactory and name == 'test':
return _factory
return default
raise NotImplementedError()
context = Context()
self.assertTrue(self._callFUT('test', context=context) is _object)
self.assertEqual(_factory_called, [((), {})])
Expand Down Expand Up @@ -1092,7 +1083,7 @@ def __conform__(self, iface):
def queryUtility(self, iface, name, default):
if iface is IFactory and name == 'test':
return _Factory()
return default
raise NotImplementedError()
context = Context()
self.assertEqual(self._callFUT('test', context=context), [IFoo])

Expand Down Expand Up @@ -1177,28 +1168,3 @@ def __init__(self, id, sm):
self.sitemanager = sm

return MyUtility(name, sm)


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Test_getSiteManager),
unittest.makeSuite(Test_getAdapterInContext),
unittest.makeSuite(Test_queryAdapterInContext),
unittest.makeSuite(Test_getAdapter),
unittest.makeSuite(Test_queryAdapter),
unittest.makeSuite(Test_getMultiAdapter),
unittest.makeSuite(Test_queryMultiAdapter),
unittest.makeSuite(Test_getAdapters),
unittest.makeSuite(Test_subscribers),
unittest.makeSuite(Test_handle),
unittest.makeSuite(Test_getUtility),
unittest.makeSuite(Test_queryUtility),
unittest.makeSuite(Test_getUtilitiesFor),
unittest.makeSuite(Test_getAllUtilitiesRegisteredFor),
unittest.makeSuite(Test_getNextUtility),
unittest.makeSuite(Test_queryNextUtility),
unittest.makeSuite(Test_createObject),
unittest.makeSuite(Test_getFactoryInterfaces),
unittest.makeSuite(Test_getFactoriesFor),
))

25 changes: 3 additions & 22 deletions src/zope/component/tests/test__declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,11 @@ def _run_generated_code(self, code, globs, locs,
fails_under_py3k=True,
):
import warnings
#from zope.component._compat import PYTHON3
PYTHON3 = False
with warnings.catch_warnings(record=True) as log:
warnings.resetwarnings()
if not PYTHON3:
exec(code, globs, locs)
self.assertEqual(len(log), 0) # no longer warn
return True
else:
try:
exec(code, globs, locs)
except TypeError:
return False
else:
if fails_under_py3k:
self.fail("Didn't raise TypeError")
exec(code, globs, locs)
self.assertEqual(len(log), 0) # no longer warn
return True

def test_instances_not_affected(self):
from zope.component._declaration import adapts
Expand Down Expand Up @@ -211,11 +200,3 @@ class Baz(object):
baz = Baz()
baz.__component_adapts__ = (IFoo, IBar)
self.assertEqual(self._callFUT(baz), (IFoo, IBar))


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Test_adapter),
unittest.makeSuite(Test_adapts),
unittest.makeSuite(Test_adaptedBy),
))
11 changes: 3 additions & 8 deletions src/zope/component/tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class IBaz(Interface):
pass
@implementer(IBaz)
def _callable():
pass
raise NotImplementedError()
factory = self._makeOne(_callable, interfaces=(IFoo, IBar))
spec = factory.getInterfaces()
self.assertEqual(spec.__name__, '_callable')
Expand All @@ -97,15 +97,10 @@ class IBaz(Interface):
pass
@implementer(IBaz)
def _callable():
pass
raise NotImplementedError()
factory = self._makeOne(_callable)
spec = factory.getInterfaces()
self.assertEqual(list(spec), [IBaz])

def _test_callable(*args, **kw):
pass

def test_suite():
return unittest.TestSuite((
unittest.makeSuite(FactoryTests),
))
raise NotImplementedError()
Loading

0 comments on commit 304af7a

Please sign in to comment.