Ausgabe der neuen DB Einträge
This commit is contained in:
parent
bad48e1627
commit
cfbbb9ee3d
2399 changed files with 843193 additions and 43 deletions
|
|
@ -0,0 +1,133 @@
|
|||
##############################################################################
|
||||
# Copyright (c) 2020 Zope Foundation and Contributors.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This software is subject to the provisions of the Zope Public License,
|
||||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
||||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE.
|
||||
##############################################################################
|
||||
|
||||
import unittest
|
||||
|
||||
from zope.interface.verify import verifyClass
|
||||
from zope.interface.verify import verifyObject
|
||||
|
||||
from zope.interface.common import ABCInterface
|
||||
from zope.interface.common import ABCInterfaceClass
|
||||
|
||||
|
||||
def iter_abc_interfaces(predicate=lambda iface: True):
|
||||
# Iterate ``(iface, classes)``, where ``iface`` is a descendent of
|
||||
# the ABCInterfaceClass passing the *predicate* and ``classes`` is
|
||||
# an iterable of classes registered to conform to that interface.
|
||||
#
|
||||
# Note that some builtin classes are registered for two distinct
|
||||
# parts of the ABC/interface tree. For example, bytearray is both ByteString
|
||||
# and MutableSequence.
|
||||
seen = set()
|
||||
stack = list(ABCInterface.dependents) # subclasses, but also implementedBy objects
|
||||
while stack:
|
||||
iface = stack.pop(0)
|
||||
if iface in seen or not isinstance(iface, ABCInterfaceClass):
|
||||
continue
|
||||
seen.add(iface)
|
||||
stack.extend(list(iface.dependents))
|
||||
if not predicate(iface):
|
||||
continue
|
||||
|
||||
registered = set(iface.getRegisteredConformers())
|
||||
registered -= set(iface._ABCInterfaceClass__ignored_classes)
|
||||
if registered:
|
||||
yield iface, registered
|
||||
|
||||
|
||||
def add_abc_interface_tests(cls, module):
|
||||
def predicate(iface):
|
||||
return iface.__module__ == module
|
||||
add_verify_tests(cls, iter_abc_interfaces(predicate))
|
||||
|
||||
|
||||
def add_verify_tests(cls, iface_classes_iter):
|
||||
cls.maxDiff = None
|
||||
for iface, registered_classes in iface_classes_iter:
|
||||
for stdlib_class in registered_classes:
|
||||
def test(self, stdlib_class=stdlib_class, iface=iface):
|
||||
if stdlib_class in self.UNVERIFIABLE or stdlib_class.__name__ in self.UNVERIFIABLE:
|
||||
self.skipTest("Unable to verify %s" % stdlib_class)
|
||||
|
||||
self.assertTrue(self.verify(iface, stdlib_class))
|
||||
|
||||
suffix = "%s_%s_%s" % (
|
||||
stdlib_class.__name__,
|
||||
iface.__module__.replace('.', '_'),
|
||||
iface.__name__
|
||||
)
|
||||
name = 'test_auto_' + suffix
|
||||
test.__name__ = name
|
||||
assert not hasattr(cls, name), (name, list(cls.__dict__))
|
||||
setattr(cls, name, test)
|
||||
|
||||
def test_ro(self, stdlib_class=stdlib_class, iface=iface):
|
||||
from zope.interface import ro
|
||||
from zope.interface import implementedBy
|
||||
from zope.interface import Interface
|
||||
self.assertEqual(
|
||||
tuple(ro.ro(iface, strict=True)),
|
||||
iface.__sro__)
|
||||
implements = implementedBy(stdlib_class)
|
||||
sro = implements.__sro__
|
||||
self.assertIs(sro[-1], Interface)
|
||||
|
||||
# Check that we got the strict C3 resolution order, unless we
|
||||
# know we cannot. Note that 'Interface' is virtual base that doesn't
|
||||
# necessarily appear at the same place in the calculated SRO as in the
|
||||
# final SRO.
|
||||
strict = stdlib_class not in self.NON_STRICT_RO
|
||||
isro = ro.ro(implements, strict=strict)
|
||||
isro.remove(Interface)
|
||||
isro.append(Interface)
|
||||
|
||||
self.assertEqual(tuple(isro), sro)
|
||||
|
||||
name = 'test_auto_ro_' + suffix
|
||||
test_ro.__name__ = name
|
||||
assert not hasattr(cls, name)
|
||||
setattr(cls, name, test_ro)
|
||||
|
||||
class VerifyClassMixin(unittest.TestCase):
|
||||
verifier = staticmethod(verifyClass)
|
||||
UNVERIFIABLE = ()
|
||||
NON_STRICT_RO = ()
|
||||
|
||||
def _adjust_object_before_verify(self, iface, x):
|
||||
return x
|
||||
|
||||
def verify(self, iface, klass, **kwargs):
|
||||
return self.verifier(iface,
|
||||
self._adjust_object_before_verify(iface, klass),
|
||||
**kwargs)
|
||||
|
||||
|
||||
class VerifyObjectMixin(VerifyClassMixin):
|
||||
verifier = staticmethod(verifyObject)
|
||||
CONSTRUCTORS = {
|
||||
}
|
||||
|
||||
def _adjust_object_before_verify(self, iface, x):
|
||||
constructor = self.CONSTRUCTORS.get(x)
|
||||
if not constructor:
|
||||
constructor = self.CONSTRUCTORS.get(iface)
|
||||
if not constructor:
|
||||
constructor = self.CONSTRUCTORS.get(x.__name__)
|
||||
if not constructor:
|
||||
constructor = x
|
||||
if constructor is unittest.SkipTest:
|
||||
self.skipTest("Cannot create " + str(x))
|
||||
|
||||
result = constructor()
|
||||
if hasattr(result, 'close'):
|
||||
self.addCleanup(result.close)
|
||||
return result
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This software is subject to the provisions of the Zope Public License,
|
||||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
||||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
##############################################################################
|
||||
"""Base Mapping tests
|
||||
"""
|
||||
from operator import __getitem__
|
||||
|
||||
def testIReadMapping(self, inst, state, absent):
|
||||
for key in state:
|
||||
self.assertEqual(inst[key], state[key])
|
||||
self.assertEqual(inst.get(key, None), state[key])
|
||||
self.assertTrue(key in inst)
|
||||
|
||||
for key in absent:
|
||||
self.assertEqual(inst.get(key, None), None)
|
||||
self.assertEqual(inst.get(key), None)
|
||||
self.assertEqual(inst.get(key, self), self)
|
||||
self.assertRaises(KeyError, __getitem__, inst, key)
|
||||
|
||||
|
||||
def test_keys(self, inst, state):
|
||||
# Return the keys of the mapping object
|
||||
inst_keys = list(inst.keys()); inst_keys.sort()
|
||||
state_keys = list(state.keys()) ; state_keys.sort()
|
||||
self.assertEqual(inst_keys, state_keys)
|
||||
|
||||
def test_iter(self, inst, state):
|
||||
# Return the keys of the mapping object
|
||||
inst_keys = list(inst); inst_keys.sort()
|
||||
state_keys = list(state.keys()) ; state_keys.sort()
|
||||
self.assertEqual(inst_keys, state_keys)
|
||||
|
||||
def test_values(self, inst, state):
|
||||
# Return the values of the mapping object
|
||||
inst_values = list(inst.values()); inst_values.sort()
|
||||
state_values = list(state.values()) ; state_values.sort()
|
||||
self.assertEqual(inst_values, state_values)
|
||||
|
||||
def test_items(self, inst, state):
|
||||
# Return the items of the mapping object
|
||||
inst_items = list(inst.items()); inst_items.sort()
|
||||
state_items = list(state.items()) ; state_items.sort()
|
||||
self.assertEqual(inst_items, state_items)
|
||||
|
||||
def test___len__(self, inst, state):
|
||||
# Return the number of items
|
||||
self.assertEqual(len(inst), len(state))
|
||||
|
||||
def testIEnumerableMapping(self, inst, state):
|
||||
test_keys(self, inst, state)
|
||||
test_items(self, inst, state)
|
||||
test_values(self, inst, state)
|
||||
test___len__(self, inst, state)
|
||||
|
||||
|
||||
class BaseTestIReadMapping(object):
|
||||
def testIReadMapping(self):
|
||||
inst = self._IReadMapping__sample()
|
||||
state = self._IReadMapping__stateDict()
|
||||
absent = self._IReadMapping__absentKeys()
|
||||
testIReadMapping(self, inst, state, absent)
|
||||
|
||||
|
||||
class BaseTestIEnumerableMapping(BaseTestIReadMapping):
|
||||
# Mapping objects whose items can be enumerated
|
||||
def test_keys(self):
|
||||
# Return the keys of the mapping object
|
||||
inst = self._IEnumerableMapping__sample()
|
||||
state = self._IEnumerableMapping__stateDict()
|
||||
test_keys(self, inst, state)
|
||||
|
||||
def test_values(self):
|
||||
# Return the values of the mapping object
|
||||
inst = self._IEnumerableMapping__sample()
|
||||
state = self._IEnumerableMapping__stateDict()
|
||||
test_values(self, inst, state)
|
||||
|
||||
def test_items(self):
|
||||
# Return the items of the mapping object
|
||||
inst = self._IEnumerableMapping__sample()
|
||||
state = self._IEnumerableMapping__stateDict()
|
||||
test_items(self, inst, state)
|
||||
|
||||
def test___len__(self):
|
||||
# Return the number of items
|
||||
inst = self._IEnumerableMapping__sample()
|
||||
state = self._IEnumerableMapping__stateDict()
|
||||
test___len__(self, inst, state)
|
||||
|
||||
def _IReadMapping__stateDict(self):
|
||||
return self._IEnumerableMapping__stateDict()
|
||||
|
||||
def _IReadMapping__sample(self):
|
||||
return self._IEnumerableMapping__sample()
|
||||
|
||||
def _IReadMapping__absentKeys(self):
|
||||
return self._IEnumerableMapping__absentKeys()
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
##############################################################################
|
||||
# Copyright (c) 2020 Zope Foundation and Contributors.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This software is subject to the provisions of the Zope Public License,
|
||||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
||||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE.
|
||||
##############################################################################
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
from zope.interface._compat import PYTHON2 as PY2
|
||||
from zope.interface.common import builtins
|
||||
|
||||
from . import VerifyClassMixin
|
||||
from . import VerifyObjectMixin
|
||||
from . import add_verify_tests
|
||||
|
||||
|
||||
class TestVerifyClass(VerifyClassMixin,
|
||||
unittest.TestCase):
|
||||
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,
|
||||
TestVerifyClass):
|
||||
CONSTRUCTORS = {
|
||||
builtins.IFile: lambda: open(__file__)
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
##############################################################################
|
||||
# Copyright (c) 2020 Zope Foundation and Contributors.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This software is subject to the provisions of the Zope Public License,
|
||||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
||||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE.
|
||||
##############################################################################
|
||||
|
||||
|
||||
import unittest
|
||||
try:
|
||||
import collections.abc as abc
|
||||
except ImportError:
|
||||
import collections as abc
|
||||
from collections import deque
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
try:
|
||||
from types import MappingProxyType
|
||||
except ImportError:
|
||||
MappingProxyType = object()
|
||||
|
||||
from zope.interface import Invalid
|
||||
|
||||
|
||||
# Note that importing z.i.c.collections does work on import.
|
||||
from zope.interface.common import collections
|
||||
|
||||
|
||||
from zope.interface._compat import PYPY
|
||||
from zope.interface._compat import PYTHON2 as PY2
|
||||
|
||||
from . import add_abc_interface_tests
|
||||
from . import VerifyClassMixin
|
||||
from . import VerifyObjectMixin
|
||||
|
||||
class TestVerifyClass(VerifyClassMixin, unittest.TestCase):
|
||||
|
||||
# Here we test some known builtin classes that are defined to implement
|
||||
# various collection interfaces as a quick sanity test.
|
||||
def test_frozenset(self):
|
||||
self.assertIsInstance(frozenset(), abc.Set)
|
||||
self.assertTrue(self.verify(collections.ISet, frozenset))
|
||||
|
||||
def test_list(self):
|
||||
self.assertIsInstance(list(), abc.MutableSequence)
|
||||
self.assertTrue(self.verify(collections.IMutableSequence, list))
|
||||
|
||||
# Here we test some derived classes.
|
||||
def test_UserList(self):
|
||||
self.assertTrue(self.verify(collections.IMutableSequence,
|
||||
collections.UserList))
|
||||
|
||||
def test_UserDict(self):
|
||||
self.assertTrue(self.verify(collections.IMutableMapping,
|
||||
collections.UserDict))
|
||||
|
||||
def test_UserString(self):
|
||||
self.assertTrue(self.verify(collections.ISequence,
|
||||
collections.UserString))
|
||||
|
||||
def test_non_iterable_UserDict(self):
|
||||
try:
|
||||
from UserDict import UserDict as NonIterableUserDict # pylint:disable=import-error
|
||||
except ImportError:
|
||||
# Python 3
|
||||
self.skipTest("No UserDict.NonIterableUserDict on Python 3")
|
||||
|
||||
with self.assertRaises(Invalid):
|
||||
self.verify(collections.IMutableMapping, NonIterableUserDict)
|
||||
|
||||
# Now we go through the registry, which should have several things,
|
||||
# mostly builtins, but if we've imported other libraries already,
|
||||
# it could contain things from outside of there too. We aren't concerned
|
||||
# about third-party code here, just standard library types. We start with a
|
||||
# blacklist of things to exclude, but if that gets out of hand we can figure
|
||||
# out a better whitelisting.
|
||||
UNVERIFIABLE = {
|
||||
# This is declared to be an ISequence, but is missing lots of methods,
|
||||
# including some that aren't part of a language protocol, such as
|
||||
# ``index`` and ``count``.
|
||||
memoryview,
|
||||
# 'pkg_resources._vendor.pyparsing.ParseResults' is registered as a
|
||||
# MutableMapping but is missing methods like ``popitem`` and ``setdefault``.
|
||||
# It's imported due to namespace packages.
|
||||
'ParseResults',
|
||||
# sqlite3.Row claims ISequence but also misses ``index`` and ``count``.
|
||||
# It's imported because...? Coverage imports it, but why do we have it without
|
||||
# coverage?
|
||||
'Row',
|
||||
}
|
||||
|
||||
if PYPY:
|
||||
UNVERIFIABLE.update({
|
||||
# collections.deque.pop() doesn't support the index= argument to
|
||||
# MutableSequence.pop(). We can't verify this on CPython because we can't
|
||||
# get the signature, but on PyPy we /can/ get the signature, and of course
|
||||
# it doesn't match.
|
||||
deque,
|
||||
# Likewise for index
|
||||
range,
|
||||
})
|
||||
if PY2:
|
||||
# pylint:disable=undefined-variable,no-member
|
||||
# There are a lot more types that are fundamentally unverifiable on Python 2.
|
||||
UNVERIFIABLE.update({
|
||||
# Missing several key methods like __getitem__
|
||||
basestring,
|
||||
# Missing __iter__ and __contains__, hard to construct.
|
||||
buffer,
|
||||
# Missing ``__contains__``, ``count`` and ``index``.
|
||||
xrange,
|
||||
# These two are missing Set.isdisjoint()
|
||||
type({}.viewitems()),
|
||||
type({}.viewkeys()),
|
||||
})
|
||||
NON_STRICT_RO = {
|
||||
}
|
||||
|
||||
add_abc_interface_tests(TestVerifyClass, collections.ISet.__module__)
|
||||
|
||||
|
||||
class TestVerifyObject(VerifyObjectMixin,
|
||||
TestVerifyClass):
|
||||
CONSTRUCTORS = {
|
||||
collections.IValuesView: {}.values,
|
||||
collections.IItemsView: {}.items,
|
||||
collections.IKeysView: {}.keys,
|
||||
memoryview: lambda: memoryview(b'abc'),
|
||||
range: lambda: range(10),
|
||||
MappingProxyType: lambda: MappingProxyType({}),
|
||||
collections.UserString: lambda: collections.UserString('abc'),
|
||||
type(iter(bytearray())): lambda: iter(bytearray()),
|
||||
type(iter(b'abc')): lambda: iter(b'abc'),
|
||||
'coroutine': unittest.SkipTest,
|
||||
type(iter({}.keys())): lambda: iter({}.keys()),
|
||||
type(iter({}.items())): lambda: iter({}.items()),
|
||||
type(iter({}.values())): lambda: iter({}.values()),
|
||||
type((i for i in range(1))): lambda: (i for i in range(3)),
|
||||
type(iter([])): lambda: iter([]),
|
||||
type(reversed([])): lambda: reversed([]),
|
||||
'longrange_iterator': unittest.SkipTest,
|
||||
'range_iterator': lambda: iter(range(3)),
|
||||
'rangeiterator': lambda: iter(range(3)),
|
||||
type(iter(set())): lambda: iter(set()),
|
||||
type(iter('')): lambda: iter(''),
|
||||
'async_generator': unittest.SkipTest,
|
||||
type(iter(tuple())): lambda: iter(tuple()),
|
||||
}
|
||||
|
||||
if PY2:
|
||||
# pylint:disable=undefined-variable,no-member
|
||||
CONSTRUCTORS.update({
|
||||
collections.IValuesView: {}.viewvalues,
|
||||
})
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2003 Zope Foundation and Contributors.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This software is subject to the provisions of the Zope Public License,
|
||||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
||||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
##############################################################################
|
||||
"""Test for datetime interfaces
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from zope.interface.verify import verifyObject, verifyClass
|
||||
from zope.interface.common.idatetime import ITimeDelta, ITimeDeltaClass
|
||||
from zope.interface.common.idatetime import IDate, IDateClass
|
||||
from zope.interface.common.idatetime import IDateTime, IDateTimeClass
|
||||
from zope.interface.common.idatetime import ITime, ITimeClass, ITZInfo
|
||||
from datetime import timedelta, date, datetime, time, tzinfo
|
||||
|
||||
class TestDateTimeInterfaces(unittest.TestCase):
|
||||
|
||||
def test_interfaces(self):
|
||||
verifyObject(ITimeDelta, timedelta(minutes=20))
|
||||
verifyObject(IDate, date(2000, 1, 2))
|
||||
verifyObject(IDateTime, datetime(2000, 1, 2, 10, 20))
|
||||
verifyObject(ITime, time(20, 30, 15, 1234))
|
||||
verifyObject(ITZInfo, tzinfo())
|
||||
verifyClass(ITimeDeltaClass, timedelta)
|
||||
verifyClass(IDateClass, date)
|
||||
verifyClass(IDateTimeClass, datetime)
|
||||
verifyClass(ITimeClass, time)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2006 Zope Foundation and Contributors.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This software is subject to the provisions of the Zope Public License,
|
||||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
||||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
##############################################################################
|
||||
import unittest
|
||||
|
||||
class TestInterfaceImport(unittest.TestCase):
|
||||
|
||||
def test_import(self):
|
||||
import zope.interface.common.interfaces as x
|
||||
self.assertIsNotNone(x)
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
##############################################################################
|
||||
# Copyright (c) 2020 Zope Foundation and Contributors.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This software is subject to the provisions of the Zope Public License,
|
||||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
||||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE.
|
||||
##############################################################################
|
||||
|
||||
|
||||
import unittest
|
||||
import io as abc
|
||||
|
||||
# Note that importing z.i.c.io does work on import.
|
||||
from zope.interface.common import io
|
||||
|
||||
from . import add_abc_interface_tests
|
||||
from . import VerifyClassMixin
|
||||
from . import VerifyObjectMixin
|
||||
|
||||
|
||||
class TestVerifyClass(VerifyClassMixin,
|
||||
unittest.TestCase):
|
||||
pass
|
||||
|
||||
add_abc_interface_tests(TestVerifyClass, io.IIOBase.__module__)
|
||||
|
||||
|
||||
class TestVerifyObject(VerifyObjectMixin,
|
||||
TestVerifyClass):
|
||||
CONSTRUCTORS = {
|
||||
abc.BufferedWriter: lambda: abc.BufferedWriter(abc.StringIO()),
|
||||
abc.BufferedReader: lambda: abc.BufferedReader(abc.StringIO()),
|
||||
abc.TextIOWrapper: lambda: abc.TextIOWrapper(abc.BytesIO()),
|
||||
abc.BufferedRandom: lambda: abc.BufferedRandom(abc.BytesIO()),
|
||||
abc.BufferedRWPair: lambda: abc.BufferedRWPair(abc.BytesIO(), abc.BytesIO()),
|
||||
abc.FileIO: lambda: abc.FileIO(__file__),
|
||||
'_WindowsConsoleIO': unittest.SkipTest,
|
||||
}
|
||||
|
||||
try:
|
||||
import cStringIO
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
CONSTRUCTORS.update({
|
||||
cStringIO.InputType: lambda cStringIO=cStringIO: cStringIO.StringIO('abc'),
|
||||
cStringIO.OutputType: cStringIO.StringIO,
|
||||
})
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
##############################################################################
|
||||
# Copyright (c) 2020 Zope Foundation and Contributors.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This software is subject to the provisions of the Zope Public License,
|
||||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
||||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
||||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE.
|
||||
##############################################################################
|
||||
|
||||
|
||||
import unittest
|
||||
import numbers as abc
|
||||
|
||||
# Note that importing z.i.c.numbers does work on import.
|
||||
from zope.interface.common import numbers
|
||||
|
||||
from . import add_abc_interface_tests
|
||||
from . import VerifyClassMixin
|
||||
from . import VerifyObjectMixin
|
||||
|
||||
|
||||
class TestVerifyClass(VerifyClassMixin,
|
||||
unittest.TestCase):
|
||||
|
||||
def test_int(self):
|
||||
self.assertIsInstance(int(), abc.Integral)
|
||||
self.assertTrue(self.verify(numbers.IIntegral, int))
|
||||
|
||||
def test_float(self):
|
||||
self.assertIsInstance(float(), abc.Real)
|
||||
self.assertTrue(self.verify(numbers.IReal, float))
|
||||
|
||||
add_abc_interface_tests(TestVerifyClass, numbers.INumber.__module__)
|
||||
|
||||
|
||||
class TestVerifyObject(VerifyObjectMixin,
|
||||
TestVerifyClass):
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue