diff options
author | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 12:29:46 +0300 |
---|---|---|
committer | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 13:14:22 +0300 |
commit | 9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80 (patch) | |
tree | a8fb3181d5947c0d78cf402aa56e686130179049 /contrib/python/zope.interface/py2/zope/interface/common/tests | |
parent | a44b779cd359f06c3ebbef4ec98c6b38609d9d85 (diff) | |
download | ydb-9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80.tar.gz |
publishFullContrib: true for ydb
<HIDDEN_URL>
commit_hash:c82a80ac4594723cebf2c7387dec9c60217f603e
Diffstat (limited to 'contrib/python/zope.interface/py2/zope/interface/common/tests')
8 files changed, 619 insertions, 0 deletions
diff --git a/contrib/python/zope.interface/py2/zope/interface/common/tests/__init__.py b/contrib/python/zope.interface/py2/zope/interface/common/tests/__init__.py new file mode 100644 index 0000000000..20230729fe --- /dev/null +++ b/contrib/python/zope.interface/py2/zope/interface/common/tests/__init__.py @@ -0,0 +1,136 @@ +############################################################################## +# 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_%s" % ( + stdlib_class.__module__.replace('.', '_'), + 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) + + if stdlib_class not in self.UNVERIFIABLE_RO: + # 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 = () + UNVERIFIABLE_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 diff --git a/contrib/python/zope.interface/py2/zope/interface/common/tests/basemapping.py b/contrib/python/zope.interface/py2/zope/interface/common/tests/basemapping.py new file mode 100644 index 0000000000..69d5a6f729 --- /dev/null +++ b/contrib/python/zope.interface/py2/zope/interface/common/tests/basemapping.py @@ -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() diff --git a/contrib/python/zope.interface/py2/zope/interface/common/tests/test_builtins.py b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_builtins.py new file mode 100644 index 0000000000..1f0d33833e --- /dev/null +++ b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_builtins.py @@ -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__) + } diff --git a/contrib/python/zope.interface/py2/zope/interface/common/tests/test_collections.py b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_collections.py new file mode 100644 index 0000000000..152626b895 --- /dev/null +++ b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_collections.py @@ -0,0 +1,181 @@ +############################################################################## +# 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 array +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', + # In Python 3.10 ``array.array`` appears as ``IMutableSequence`` but it + # does not provide a ``clear()`` method and it cannot be instantiated + # using ``array.array()``. + array.array, + } + + 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 = { + } + else: + UNVERIFIABLE_RO = { + # ``array.array`` fails the ``test_auto_ro_*`` tests with and + # without strict RO but only on Windows (AppVeyor) on Python 3.10.0 + # (in older versions ``array.array`` does not appear as + # ``IMutableSequence``). + array.array, + } + +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, + }) + else: + UNVERIFIABLE_RO = { + # ``array.array`` fails the ``test_auto_ro_*`` tests with and + # without strict RO but only on Windows (AppVeyor) on Python 3.10.0 + # (in older versions ``array.array`` does not appear as + # ``IMutableSequence``). + array.array, + } diff --git a/contrib/python/zope.interface/py2/zope/interface/common/tests/test_idatetime.py b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_idatetime.py new file mode 100644 index 0000000000..496a5c94d7 --- /dev/null +++ b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_idatetime.py @@ -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) diff --git a/contrib/python/zope.interface/py2/zope/interface/common/tests/test_import_interfaces.py b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_import_interfaces.py new file mode 100644 index 0000000000..fe3766f6ab --- /dev/null +++ b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_import_interfaces.py @@ -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) diff --git a/contrib/python/zope.interface/py2/zope/interface/common/tests/test_io.py b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_io.py new file mode 100644 index 0000000000..c6ff8bd48d --- /dev/null +++ b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_io.py @@ -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, + }) diff --git a/contrib/python/zope.interface/py2/zope/interface/common/tests/test_numbers.py b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_numbers.py new file mode 100644 index 0000000000..abf96958d4 --- /dev/null +++ b/contrib/python/zope.interface/py2/zope/interface/common/tests/test_numbers.py @@ -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 |