2017-11-20 03:24:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-01 03:51:19 +00:00
|
|
|
# Copyright 2018 Joshua Bronson. All Rights Reserved.
|
2017-11-20 03:24:08 +00:00
|
|
|
#
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
squashed changes for 0.13.0
- support Python 3.6, refactor CI/test setup, increase test coverage
- refactor BidirectionalMapping, BidictBase, OrderedBidictBase,
FrozenBidictBase, and subclasses
- move frozenorderedbidict into _frozen and looseorderedbidict into _loose
- register bidict as a virtual subclass of MutableMapping rather than
inheriting from it directly. This makes it clearer that it does not use any
of the concrete generic methods that MutableMapping provides.
- improve performance and flexibility of frozenbidict and
frozenorderedbidict hashing
- docs, including new type-hierarchy.png diagram
- rm unused imap, ifilter, izip_longest from compat, add PYPY
- update to latest versions of dependencies
- restore benchmarking on travis
2017-01-09 15:37:31 +00:00
|
|
|
"""
|
|
|
|
Test that if foreign code provides a class that conforms to
|
|
|
|
BidirectionalMapping's interface, it is automatically a subclass.
|
|
|
|
"""
|
2017-11-20 03:24:08 +00:00
|
|
|
|
squashed changes for 0.13.0
- support Python 3.6, refactor CI/test setup, increase test coverage
- refactor BidirectionalMapping, BidictBase, OrderedBidictBase,
FrozenBidictBase, and subclasses
- move frozenorderedbidict into _frozen and looseorderedbidict into _loose
- register bidict as a virtual subclass of MutableMapping rather than
inheriting from it directly. This makes it clearer that it does not use any
of the concrete generic methods that MutableMapping provides.
- improve performance and flexibility of frozenbidict and
frozenorderedbidict hashing
- docs, including new type-hierarchy.png diagram
- rm unused imap, ifilter, izip_longest from compat, add PYPY
- update to latest versions of dependencies
- restore benchmarking on travis
2017-01-09 15:37:31 +00:00
|
|
|
from bidict import BidirectionalMapping
|
|
|
|
|
|
|
|
|
2017-11-20 03:24:08 +00:00
|
|
|
class MyBidirectionalMapping(dict):
|
2017-11-16 20:44:51 +00:00
|
|
|
"""Dummy type implementing the BidirectionalMapping interface."""
|
2017-11-21 15:35:51 +00:00
|
|
|
|
squashed changes for 0.13.0
- support Python 3.6, refactor CI/test setup, increase test coverage
- refactor BidirectionalMapping, BidictBase, OrderedBidictBase,
FrozenBidictBase, and subclasses
- move frozenorderedbidict into _frozen and looseorderedbidict into _loose
- register bidict as a virtual subclass of MutableMapping rather than
inheriting from it directly. This makes it clearer that it does not use any
of the concrete generic methods that MutableMapping provides.
- improve performance and flexibility of frozenbidict and
frozenorderedbidict hashing
- docs, including new type-hierarchy.png diagram
- rm unused imap, ifilter, izip_longest from compat, add PYPY
- update to latest versions of dependencies
- restore benchmarking on travis
2017-01-09 15:37:31 +00:00
|
|
|
def __inverted__(self):
|
|
|
|
for (key, val) in self.items():
|
|
|
|
yield (val, key)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def inv(self):
|
2017-11-16 20:44:51 +00:00
|
|
|
"""Like :attr:`bidict.bidict.inv`."""
|
2017-11-20 03:24:08 +00:00
|
|
|
return MyBidirectionalMapping(self.__inverted__())
|
squashed changes for 0.13.0
- support Python 3.6, refactor CI/test setup, increase test coverage
- refactor BidirectionalMapping, BidictBase, OrderedBidictBase,
FrozenBidictBase, and subclasses
- move frozenorderedbidict into _frozen and looseorderedbidict into _loose
- register bidict as a virtual subclass of MutableMapping rather than
inheriting from it directly. This makes it clearer that it does not use any
of the concrete generic methods that MutableMapping provides.
- improve performance and flexibility of frozenbidict and
frozenorderedbidict hashing
- docs, including new type-hierarchy.png diagram
- rm unused imap, ifilter, izip_longest from compat, add PYPY
- update to latest versions of dependencies
- restore benchmarking on travis
2017-01-09 15:37:31 +00:00
|
|
|
|
|
|
|
|
2018-02-13 01:34:33 +00:00
|
|
|
class OldStyleClass: # pylint: disable=old-style-class,no-init
|
2017-11-20 03:24:08 +00:00
|
|
|
"""In Python 2 this is an old-style class (not derived from object)."""
|
2017-03-13 17:22:56 +00:00
|
|
|
|
|
|
|
|
2017-11-20 03:24:08 +00:00
|
|
|
def test_bidi_mapping_subclasshook():
|
|
|
|
"""Ensure issubclass(foo, BidirectionalMapping) works as expected."""
|
|
|
|
assert issubclass(MyBidirectionalMapping, BidirectionalMapping)
|
squashed changes for 0.13.0
- support Python 3.6, refactor CI/test setup, increase test coverage
- refactor BidirectionalMapping, BidictBase, OrderedBidictBase,
FrozenBidictBase, and subclasses
- move frozenorderedbidict into _frozen and looseorderedbidict into _loose
- register bidict as a virtual subclass of MutableMapping rather than
inheriting from it directly. This makes it clearer that it does not use any
of the concrete generic methods that MutableMapping provides.
- improve performance and flexibility of frozenbidict and
frozenorderedbidict hashing
- docs, including new type-hierarchy.png diagram
- rm unused imap, ifilter, izip_longest from compat, add PYPY
- update to latest versions of dependencies
- restore benchmarking on travis
2017-01-09 15:37:31 +00:00
|
|
|
assert not issubclass(dict, BidirectionalMapping)
|
2017-11-20 03:24:08 +00:00
|
|
|
# Make sure this works with old-style classes as expected.
|
|
|
|
assert not issubclass(OldStyleClass, BidirectionalMapping)
|