Skip to content

Commit

Permalink
Cleanups per review.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Feb 17, 2020
1 parent d088fd5 commit 2b49157
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/zope/interface/common/__init__.py
Expand Up @@ -110,7 +110,7 @@ class ABCInterfaceClass(InterfaceClass):
classes specifically registered with the ABC should be declared to
do so.
.. verisonadded:: 5.0
.. versionadded:: 5.0.0
"""

# If we could figure out invalidation, and used some special
Expand Down
19 changes: 10 additions & 9 deletions src/zope/interface/common/io.py
Expand Up @@ -21,14 +21,6 @@
from __future__ import absolute_import

import io as abc
try:
import cStringIO
import StringIO
except ImportError:
# Python 3
extra_buffered_io_base = ()
else:
extra_buffered_io_base = (StringIO.StringIO, cStringIO.InputType, cStringIO.OutputType)

from zope.interface.common import ABCInterface

Expand All @@ -45,7 +37,16 @@ class IRawIOBase(IIOBase):

class IBufferedIOBase(IIOBase):
abc = abc.BufferedIOBase
extra_classes = extra_buffered_io_base
try:
import cStringIO
except ImportError:
# Python 3
extra_classes = ()
else:
import StringIO
extra_classes = (StringIO.StringIO, cStringIO.InputType, cStringIO.OutputType)
del cStringIO
del StringIO


class ITextIOBase(IIOBase):
Expand Down
1 change: 1 addition & 0 deletions src/zope/interface/common/numbers.py
Expand Up @@ -45,6 +45,7 @@ def __complex__():
"""
Rarely implemented, even in builtin types.
"""

if PY2:
@optional
def __eq__(other):
Expand Down
11 changes: 8 additions & 3 deletions src/zope/interface/common/tests/__init__.py
Expand Up @@ -46,8 +46,11 @@ def iter_abc_interfaces(predicate=lambda iface: True):
def add_abc_interface_tests(cls, module):
def predicate(iface):
return iface.__module__ == module
add_verify_tests(cls, iter_abc_interfaces(predicate))

for iface, registered_classes in iter_abc_interfaces(predicate):

def add_verify_tests(cls, iface_classes_iter):
for iface, registered_classes in iface_classes_iter:
for stdlib_class in registered_classes:

def test(self, stdlib_class=stdlib_class, iface=iface):
Expand All @@ -62,7 +65,6 @@ def test(self, stdlib_class=stdlib_class, iface=iface):
setattr(cls, name, test)



class VerifyClassMixin(unittest.TestCase):
verifier = staticmethod(verifyClass)
UNVERIFIABLE = ()
Expand Down Expand Up @@ -92,4 +94,7 @@ def _adjust_object_before_verify(self, iface, x):
if constructor is unittest.SkipTest:
self.skipTest("Cannot create " + str(x))

return constructor()
result = constructor()
if hasattr(result, 'close'):
self.addCleanup(result.close)
return result
42 changes: 14 additions & 28 deletions src/zope/interface/common/tests/test_builtins.py
Expand Up @@ -18,38 +18,24 @@

from . import VerifyClassMixin
from . import VerifyObjectMixin
from . import add_verify_tests


class TestVerifyClass(VerifyClassMixin,
unittest.TestCase):
UNVERIFIABLE = (

)
FILE_IMPL = ()
if PY2:
FILE_IMPL = ((file, builtins.IFile),)
@classmethod
def create_tests(cls):
for klass, iface in (
(list, builtins.IList),
(tuple, builtins.ITuple),
(type(u'abc'), builtins.ITextString),
(bytes, builtins.IByteString),
(str, builtins.INativeString),
(bool, builtins.IBool),
(dict, builtins.IDict),
) + cls.FILE_IMPL:
def test(self, klass=klass, iface=iface):
if klass in self.UNVERIFIABLE:
self.skipTest("Cannot verify %s" % klass)

self.assertTrue(self.verify(iface, klass))

name = 'test_auto_' + klass.__name__ + '_' + iface.__name__
test.__name__ = name
setattr(cls, name, test)

TestVerifyClass.create_tests()
pass


add_verify_tests(TestVerifyClass, (
(builtins.IList, (list,)),
(builtins.ITuple, (tuple,)),
(builtins.ITextString, (type(u'abc'),)),
(builtins.IByteString, (bytes,)),
(builtins.INativeString, (str,)),
(builtins.IBool, (bool,)),
(builtins.IDict, (dict,)),
(builtins.IFile, (file,) if PY2 else ()),
))


class TestVerifyObject(VerifyObjectMixin,
Expand Down

0 comments on commit 2b49157

Please sign in to comment.