00000035
  7   Kˆl–ß=¿JÕ4Ÿº‚ „ Z¸&î¥1hß�þC�,ÙdmÆð„ãÀþõƒt"{ôÝÀò Ø    K##############################################################################
# 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({
            # col