Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100% coverage #30

Merged
merged 1 commit into from
Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[run]
source = zope.component
omit =
src/zope/component/standalonetests.py
# Runs in a subprocess

[report]
exclude_lines =
pragma: no cover
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
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ Changes

- Drop support for "setup.py test".

- Code coverage reports are now `produced and hosted by coveralls.io
<https://coveralls.io/github/zopefoundation/zope.component>`_, and
PRs must keep them at 100%.

- Internal test code in ``zope.component.testfiles`` has been adjusted
and in some cases removed.

4.3.0 (2016-08-26)
------------------

Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ include *.py
include .travis.yml
include buildout.cfg
include tox.ini
include .coveragerc

prune docs/_build
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@

.. image:: https://travis-ci.org/zopefoundation/zope.component.png?branch=master
:target: https://travis-ci.org/zopefoundation/zope.component
:alt: Build Status

.. image:: https://readthedocs.org/projects/zopecomponent/badge/?version=latest
:target: http://zopecomponent.readthedocs.org/en/latest/
:alt: Documentation Status

.. image:: https://coveralls.io/repos/github/zopefoundation/zope.component/badge.svg?branch=master
:target: https://coveralls.io/github/zopefoundation/zope.component?branch=master
:alt: Coverage Status


.. note::

This package is intended to be independently reusable in any Python
Expand Down
15 changes: 12 additions & 3 deletions docs/testlayer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,33 @@ 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 that are used `to
conditionally control processing of certain directives
<http://zopeconfiguration.readthedocs.io/en/latest/narr.html#making-specific-directives-conditional>`_
(here we use "devmode", a common condition for controlling development
options like debugging output).

.. 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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def read(*rnames):
+ '\n' +
read('CHANGES.rst')
),
keywords="interface component coupling loose utility adapter",
packages=find_packages('src'),
package_dir={'': 'src'},
classifiers=[
Expand Down
5 changes: 3 additions & 2 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
def write(x):
sys.stdout.write('%s\n' % x)

if __name__ == "__main__": #pragma NO COVER (runs in subprocess)
if __name__ == "__main__":
if sys.version_info[0] >= 3:
# TextIO? Are you kidding me?
data = sys.stdin.buffer.read()
Expand Down
4 changes: 0 additions & 4 deletions src/zope/component/testfiles/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ class Comp2(object):
def __init__(self, context):
self.context = context

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

@adapter(IContent)
@implementer(IApp)
@named('app')
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
24 changes: 23 additions & 1 deletion src/zope/component/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# tests package
import unittest

def skipIfNoSecurity(testfunc):
try:
import zope.security
except ImportError:
return unittest.skip("zope.security not installed")(testfunc)
return testfunc

def fails_if_called(test, msg="This function must not be called.",
arguments=True):
"""
Return a new function (accepting any arguments)
that will call test.fail(msg) if it is called.

:keyword bool arguments: If set to ``False``, then we will
not accept any arguments. This can avoid
masking when we would expect a TypeError to be raised by
calling an instance method against a class.
"""
if not arguments:
return lambda: test.fail(msg)
return lambda *_args, **__kwargs: test.fail(msg)
8 changes: 0 additions & 8 deletions src/zope/component/tests/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class ISI(Interface):
class ISII(Interface):
pass

def noop(*args):
pass

class U(object):

def __init__(self, name):
Expand Down Expand Up @@ -121,11 +118,6 @@ def __init__(self, context):

comp = Comp(1)

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


class ConformsToIComponentLookup(object):
"""Allow a dummy sitemanager to conform/adapt to `IComponentLookup`."""
Expand Down
Loading