Skip to content

Commit

Permalink
Fix DeprecationWarnings, drop setup.py test.
Browse files Browse the repository at this point in the history
Also reach 100% coverage.
  • Loading branch information
jamadden committed Oct 19, 2018
1 parent b876ffc commit f1037ca
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 35 deletions.
18 changes: 10 additions & 8 deletions CHANGES.rst
@@ -1,22 +1,24 @@
Changes
=======
=========
Changes
=========

2.1.1 (unreleased)
------------------
==================

- Add support for Python 3.7.

- Drop support for ``setup.py test``.

2.1.0 (2017-07-25)
------------------
==================

- Add support for Python 3.5 and 3.6.

- Drop support for Python 2.6 and 3.3.


2.0.0 (2014-12-24)
------------------
==================

- Added support for PyPy. (PyPy3 is pending release of a fix for:
https://bitbucket.org/pypy/pypy/issue/1946)
Expand All @@ -27,7 +29,7 @@ Changes


2.0.0a1 (2013-02-25)
--------------------
====================

- Add support for Python 3.3.

Expand All @@ -44,15 +46,15 @@ Changes


1.0.1 (2010-09-25)
------------------
==================

- Add undeclared but needed dependency on ``zope.component``.

- Add test extra to declare test dependency on ``zope.component[test]``.


1.0 (2009-05-19)
----------------
================

* Initial public release, derived from zope.app.component and
zope.app.interface to replace them.
15 changes: 0 additions & 15 deletions setup.py
Expand Up @@ -20,20 +20,6 @@ def read(*rnames):
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()

def alltests():
import sys
import unittest
# use the zope.testrunner machinery to find all the
# test suites we've put under ourselves
import zope.testrunner.find
import zope.testrunner.options
here = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))
args = sys.argv[:]
defaults = ["--test-path", here]
options = zope.testrunner.options.get_options(args, defaults)
suites = list(zope.testrunner.find.find_suites(options))
return unittest.TestSuite(suites)

TEST_REQUIRES = [
'zope.configuration',
'zope.testing',
Expand Down Expand Up @@ -89,7 +75,6 @@ def alltests():
'test': TEST_REQUIRES,
},
tests_require=TEST_REQUIRES,
test_suite='__main__.alltests',
include_package_data=True,
zip_safe=False,
)
8 changes: 4 additions & 4 deletions src/zope/componentvocabulary/tests/test_configure.py
Expand Up @@ -21,11 +21,11 @@
class ZCMLTest(unittest.TestCase):

def test_configure_zcml_should_be_loadable(self):
try:
zope.configuration.xmlconfig.XMLConfig(
# If this raises, let it be a test error.
# We get a more clear exception than if we catch
# what it raises and do self.fail(ex)
zope.configuration.xmlconfig.XMLConfig(
'configure.zcml', zope.componentvocabulary)()
except Exception as e:
self.fail(e)

def test_configure_should_register_n_utilities(self):
gsm = zope.component.getGlobalSiteManager()
Expand Down
51 changes: 49 additions & 2 deletions src/zope/componentvocabulary/tests/test_vocabulary.py
Expand Up @@ -16,8 +16,51 @@
__docformat__ = "reStructuredText"
import doctest
import re
import unittest

from zope.testing import renormalizing


class TestUtilityComponentInterfacesVocabulary(unittest.TestCase):

def _getTargetClass(self):
from zope.componentvocabulary.vocabulary import UtilityComponentInterfacesVocabulary
return UtilityComponentInterfacesVocabulary

def _makeOne(self, context):
return self._getTargetClass()(context)

def test_construct_without_registration(self):
context = object()
vocab = self._makeOne(context)

self.assertIsNotNone(vocab.getTermByToken('zope.interface.Interface'))

def test_construct_with_registration_unwraps(self):
from zope.interface import Interface
from zope.interface import implementer
from zope.interface.interfaces import IUtilityRegistration

@implementer(IUtilityRegistration)
class Reg(object):
def __init__(self, component):
self.component = component

class IComponent(Interface):
"A component interface"

@implementer(IComponent)
class Component(object):
"A component"


reg = Reg(Component())

vocab = self._makeOne(reg)
self.assertIsNotNone(
vocab.getTermByToken('zope.componentvocabulary.tests.test_vocabulary.IComponent'))


checker = renormalizing.RENormalizing([
# Python 3 unicode removed the "u".
(re.compile("u('.*?')"),
Expand All @@ -28,5 +71,9 @@


def test_suite():
return doctest.DocTestSuite(
'zope.componentvocabulary.vocabulary', checker=checker)
suite = unittest.defaultTestLoader.loadTestsFromName(__name__)
suite.addTest(
doctest.DocTestSuite(
'zope.componentvocabulary.vocabulary', checker=checker)
)
return suite
23 changes: 20 additions & 3 deletions src/zope/componentvocabulary/vocabulary.py
Expand Up @@ -20,9 +20,9 @@
import six
import zope.component
from zope.component.interface import interfaceToName
from zope.component.interfaces import IUtilityRegistration
from zope.interface import implementer, provider, Interface, providedBy
from zope.interface.interfaces import IInterface
from zope.interface.interfaces import IUtilityRegistration
from zope.security.proxy import removeSecurityProxy
from zope.schema.interfaces import IVocabularyTokenized
from zope.schema.interfaces import ITokenizedTerm, ITitledTokenizedTerm
Expand Down Expand Up @@ -287,7 +287,7 @@ def __init__(self, context):


@implementer(ITitledTokenizedTerm)
class UtilityNameTerm:
class UtilityNameTerm(object):
r"""Simple term that provides a utility name as a value.
>>> t1 = UtilityNameTerm('abc')
Expand Down Expand Up @@ -338,7 +338,7 @@ def title(self):


@implementer(IVocabularyTokenized)
class UtilityNames:
class UtilityNames(object):
"""Vocabulary with utility names for a single interface as values.
>>> class IMyUtility(Interface):
Expand Down Expand Up @@ -380,6 +380,15 @@ class UtilityNames:
>>> u'three' in vocab
True
If the term is not found, a ValueError is raised from ``getTerm``
>>> u'four' in vocab
False
>>> vocab.getTerm(u'four')
Traceback (most recent call last):
...
ValueError: four
>>> component.provideUtility(MyUtility(), IMyUtility)
>>> u'' in vocab
True
Expand All @@ -394,6 +403,14 @@ class UtilityNames:
>>> term3.value
u'one'
If we ask ``getTermByToken`` to find a missing token, a
``LookupError`` is raised:
>>> vocab.getTermByToken(u'no such term')
Traceback (most recent call last):
...
LookupError: no matching token: 'no such term'
>>> ps.tearDown()
"""

Expand Down
8 changes: 5 additions & 3 deletions tox.ini
Expand Up @@ -5,14 +5,16 @@ envlist =
[testenv]
usedevelop = true
commands =
python setup.py -q test -q
zope-testrunner --test-path=src
deps =
.[test]

[testenv:coverage]
basepython =
python3.6
commands =
coverage run setup.py -q test -q
coverage report
coverage run -m zope.testrunner --test-path=src
coverage report --fail-under=100
deps =
{[testenv]deps}
coverage

0 comments on commit f1037ca

Please sign in to comment.