Skip to content
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
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[run]
branch = True
source = zope.interface

[report]
Expand All @@ -8,4 +9,3 @@ exclude_lines =
class I[A-Z]\w+\((Interface|I[A-Z].*)\):
raise NotImplementedError
self\.fail
@_skip_under_py2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.so
__pycache__
.coverage
.coverage.*
.installed.cfg
nosetests.xml
coverage.xml
Expand Down
8 changes: 4 additions & 4 deletions src/zope/interface/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sys
import types

if sys.version_info[0] < 3: #pragma NO COVER
if sys.version_info[0] < 3:

def _normalize_name(name):
if isinstance(name, basestring):
Expand All @@ -31,7 +31,7 @@ def _normalize_name(name):
PYTHON3 = False
PYTHON2 = True

else: # pragma: no cover
else:

def _normalize_name(name):
if isinstance(name, bytes):
Expand All @@ -48,11 +48,11 @@ def _normalize_name(name):
PYTHON3 = True
PYTHON2 = False

def _skip_under_py3k(test_method): # pragma: no cover
def _skip_under_py3k(test_method):
import unittest
return unittest.skipIf(sys.version_info[0] >= 3, "Only on Python 2")(test_method)


def _skip_under_py2(test_method): # pragma: no cover
def _skip_under_py2(test_method):
import unittest
return unittest.skipIf(sys.version_info[0] < 3, "Only on Python 3")(test_method)
4 changes: 2 additions & 2 deletions src/zope/interface/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def subscriptions(self, required, provided):

try:
from zope.interface._zope_interface_coptimizations import LookupBase
except ImportError: # pragma: no cover
except ImportError:
LookupBase = LookupBaseFallback


Expand Down Expand Up @@ -446,7 +446,7 @@ def subscriptions(self, required, provided):

try:
from zope.interface._zope_interface_coptimizations import VerifyingBase
except ImportError: # pragma: no cover
except ImportError:
VerifyingBase = VerifyingBaseFallback


Expand Down
4 changes: 2 additions & 2 deletions src/zope/interface/advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from types import FunctionType
try:
from types import ClassType
except ImportError: # pragma: no cover Python > 3.x
except ImportError:
__python3 = True
else: # pragma: no cover Python < 3.x
else:
__python3 = False

import sys
Expand Down
18 changes: 8 additions & 10 deletions src/zope/interface/declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,6 @@ def __call__(self, ob):
def _implements(name, interfaces, classImplements):
# This entire approach is invalid under Py3K. Don't even try to fix
# the coverage for this block there. :(
if PYTHON3: # pragma: no cover
raise TypeError('Class advice impossible in Python3')
frame = sys._getframe(2)
locals = frame.f_locals

Expand Down Expand Up @@ -481,7 +479,7 @@ def implements(*interfaces):
"""
# This entire approach is invalid under Py3K. Don't even try to fix
# the coverage for this block there. :(
if PYTHON3: # pragma: no cover
if PYTHON3:
raise TypeError(_ADVICE_ERROR % 'implementer')
_implements("implements", interfaces, classImplements)

Expand Down Expand Up @@ -509,7 +507,7 @@ def implementsOnly(*interfaces):
"""
# This entire approach is invalid under Py3K. Don't even try to fix
# the coverage for this block there. :(
if PYTHON3: # pragma: no cover
if PYTHON3:
raise TypeError(_ADVICE_ERROR % 'implementer_only')
_implements("implementsOnly", interfaces, classImplementsOnly)

Expand Down Expand Up @@ -581,7 +579,7 @@ def directlyProvides(object, *interfaces):
# Note that we can't get here from Py3k tests: there is no normal
# class which isn't descriptor aware.
if not isinstance(object,
DescriptorAwareMetaClasses): # pragma: no cover Py3k
DescriptorAwareMetaClasses):
raise TypeError("Attempt to make an interface declaration on a "
"non-descriptor-aware class")

Expand Down Expand Up @@ -641,9 +639,9 @@ def __get__(self, inst, cls):
# Try to get C base:
try:
import zope.interface._zope_interface_coptimizations
except ImportError: # pragma: no cover
except ImportError:
pass
else: # pragma: no cover
else:
from zope.interface._zope_interface_coptimizations import ClassProvidesBase


Expand Down Expand Up @@ -715,7 +713,7 @@ def classProvides(*interfaces):
# This entire approach is invalid under Py3K. Don't even try to fix
# the coverage for this block there. :(

if PYTHON3: # pragma: no cover
if PYTHON3:
raise TypeError(_ADVICE_ERROR % 'provider')

frame = sys._getframe(1)
Expand Down Expand Up @@ -918,9 +916,9 @@ def _normalizeargs(sequence, output = None):

try:
import zope.interface._zope_interface_coptimizations
except ImportError: # pragma: no cover
except ImportError:
pass
else: # pragma: no cover PyPy
else:
from zope.interface._zope_interface_coptimizations import implementedBy
from zope.interface._zope_interface_coptimizations import providedBy
from zope.interface._zope_interface_coptimizations import (
Expand Down
6 changes: 3 additions & 3 deletions src/zope/interface/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def isOrExtends(self, interface):
SpecificationBase = SpecificationBasePy
try:
from zope.interface._zope_interface_coptimizations import SpecificationBase
except ImportError: # pragma: no cover
except ImportError:
pass

_marker = object()
Expand Down Expand Up @@ -156,14 +156,14 @@ def __adapt__(self, obj):
InterfaceBase = InterfaceBasePy
try:
from zope.interface._zope_interface_coptimizations import InterfaceBase
except ImportError: # pragma: no cover
except ImportError:
pass


adapter_hooks = []
try:
from zope.interface._zope_interface_coptimizations import adapter_hooks
except ImportError: # pragma: no cover
except ImportError:
pass


Expand Down
2 changes: 1 addition & 1 deletion src/zope/interface/tests/advisory_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def pong(klass):
class ClassicClass:
__metaclass__ = ClassType
classLevelFrameInfo = getFrameInfo(sys._getframe())
except ImportError: # pragma: no cover (Py3, this module may not even be imported)
except ImportError:
ClassicClass = None

class NewStyleClass:
Expand Down
2 changes: 1 addition & 1 deletion src/zope/interface/tests/odd.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __getattribute__(cls, name):
if name == '__class__':
return cls
# Under Python 3.6, __prepare__ gets requested
return type.__getattribute__(cls, name) # pragma: no cover
return type.__getattribute__(cls, name)


class MetaClass(object):
Expand Down
6 changes: 3 additions & 3 deletions src/zope/interface/tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def test_optimizations(self):
from zope.interface.adapter import LookupBaseFallback
try:
import zope.interface._zope_interface_coptimizations
except ImportError: # pragma: no cover (pypy)
except ImportError:
self.assertIs(self._getTargetClass(), LookupBaseFallback)
else:
self.assertIsNot(self._getTargetClass(), LookupBaseFallback)
Expand Down Expand Up @@ -729,7 +729,7 @@ def test_optimizations(self):
from zope.interface.adapter import VerifyingBaseFallback
try:
import zope.interface._zope_interface_coptimizations
except ImportError: # pragma: no cover (pypy)
except ImportError:
self.assertIs(self._getTargetClass(), VerifyingBaseFallback)
else:
self.assertIsNot(self._getTargetClass(), VerifyingBaseFallback)
Expand Down Expand Up @@ -1390,7 +1390,7 @@ def test__normalize_name_str(self):
STR = b'str'
if sys.version_info[0] < 3:
self.assertEqual(_normalize_name(STR), unicode(STR))
else: # pragma: no cover (tox runs coverage on Python 2)
else:
self.assertEqual(_normalize_name(STR), str(STR, 'ascii'))

def test__normalize_name_unicode(self):
Expand Down
33 changes: 19 additions & 14 deletions src/zope/interface/tests/test_declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _run_generated_code(self, code, globs, locs,
exec(code, globs, locs)
self.assertEqual(len(log), 0) # no longer warn
return True
else: # pragma: no cover (tox runs coverage on Python 2)
else:
try:
exec(code, globs, locs)
except TypeError:
Expand Down Expand Up @@ -339,10 +339,14 @@ class Foo(object):

def test_dictless_wo_existing_Implements_cant_assign___implemented__(self):
class Foo(object):
def _get_impl(self): return None
def _set_impl(self, val): raise TypeError
def _get_impl(self):
raise NotImplementedError()
def _set_impl(self, val):
raise TypeError
__implemented__ = property(_get_impl, _set_impl)
def __call__(self): pass #act like a factory
def __call__(self):
# act like a factory
raise NotImplementedError()
foo = Foo()
self.assertRaises(TypeError, self._callFUT, foo)

Expand Down Expand Up @@ -479,7 +483,7 @@ def test_optimizations(self):
from zope.interface.declarations import implementedBy
try:
import zope.interface._zope_interface_coptimizations
except ImportError: # pragma: no cover (pypy)
except ImportError:
self.assertIs(implementedBy, implementedByFallback)
else:
self.assertIsNot(implementedBy, implementedByFallback)
Expand Down Expand Up @@ -685,15 +689,17 @@ def test_function(self):
from zope.interface.interface import InterfaceClass
IFoo = InterfaceClass('IFoo')
decorator = self._makeOne(IFoo)
def _function(): pass
def _function():
raise NotImplementedError()
self.assertRaises(ValueError, decorator, _function)

def test_method(self):
from zope.interface.interface import InterfaceClass
IFoo = InterfaceClass('IFoo')
decorator = self._makeOne(IFoo)
class Bar:
def _method(): pass
def _method():
raise NotImplementedError()
self.assertRaises(ValueError, decorator, Bar._method)

def test_oldstyle_class(self):
Expand Down Expand Up @@ -752,9 +758,8 @@ def test_simple(self):
warnings.resetwarnings()
try:
exec(CODE, globs, locs)
except TypeError: # pragma: no cover (tox runs coverage on Python 2)
if not PYTHON3:
raise
except TypeError:
self.assertTrue(PYTHON3, "Must be Python 3")
else:
if PYTHON3:
self.fail("Didn't raise TypeError")
Expand Down Expand Up @@ -1130,7 +1135,7 @@ def test_optimizations(self):
from zope.interface.declarations import ClassProvidesBaseFallback
try:
import zope.interface._zope_interface_coptimizations
except ImportError: # pragma: no cover (pypy)
except ImportError:
self.assertIs(self._getTargetClass(), ClassProvidesBaseFallback)
else:
self.assertIsNot(self._getTargetClass(), ClassProvidesBaseFallback)
Expand Down Expand Up @@ -1441,7 +1446,7 @@ def test_optimizations(self):
from zope.interface.declarations import getObjectSpecification
try:
import zope.interface._zope_interface_coptimizations
except ImportError: # pragma: no cover (pypy)
except ImportError:
self.assertIs(getObjectSpecification,
getObjectSpecificationFallback)
else:
Expand Down Expand Up @@ -1538,7 +1543,7 @@ def test_optimizations(self):
from zope.interface.declarations import providedBy
try:
import zope.interface._zope_interface_coptimizations
except ImportError: # pragma: no cover (pypy)
except ImportError:
self.assertIs(providedBy, providedByFallback)
else:
self.assertIsNot(providedBy, providedByFallback)
Expand Down Expand Up @@ -1609,7 +1614,7 @@ def test_optimizations(self):
ObjectSpecificationDescriptorFallback)
try:
import zope.interface._zope_interface_coptimizations
except ImportError: # pragma: no cover (pypy)
except ImportError:
self.assertIs(self._getTargetClass(),
ObjectSpecificationDescriptorFallback)
else:
Expand Down
11 changes: 4 additions & 7 deletions src/zope/interface/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ def _getTargetClass(self):
from zope.interface.exceptions import DoesNotImplement
return DoesNotImplement

def _makeOne(self, iface=None):
if iface is None:
iface = _makeIface()
def _makeOne(self):
iface = _makeIface()
return self._getTargetClass()(iface)

def test___str__(self):
Expand All @@ -45,9 +44,8 @@ def _getTargetClass(self):
from zope.interface.exceptions import BrokenImplementation
return BrokenImplementation

def _makeOne(self, iface=None, name='missing'):
if iface is None:
iface = _makeIface()
def _makeOne(self, name='missing'):
iface = _makeIface()
return self._getTargetClass()(iface, name)

def test___str__(self):
Expand All @@ -72,4 +70,3 @@ def test___str__(self):
self.assertEqual(str(dni),
'The implementation of aMethod violates its contract\n'
' because I said so.\n ')

Loading