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/.
|
|
|
|
|
2017-11-18 03:35:40 +00:00
|
|
|
Test for consistency in ordered bidicts after handling duplicate keys/values
|
|
|
|
(when passing python's -O flag, this would previously fail
|
|
|
|
due to reliance on side effects in assert statements)::
|
|
|
|
|
|
|
|
>>> from bidict import OrderedBidict, DuplicationError, RAISE, OVERWRITE
|
|
|
|
>>> b = OrderedBidict([(0, 1)])
|
2018-02-19 07:53:03 +00:00
|
|
|
>>> exc = None
|
2017-11-18 03:35:40 +00:00
|
|
|
>>> try:
|
|
|
|
... b.update([(0, 2), (3, 4), (5, 4)])
|
2018-02-19 07:53:03 +00:00
|
|
|
... except DuplicationError as e:
|
|
|
|
... exc = e
|
|
|
|
>>> exc is not None
|
|
|
|
True
|
2017-11-18 03:35:40 +00:00
|
|
|
>>> len(b.inv)
|
|
|
|
1
|
2018-02-27 13:09:57 +00:00
|
|
|
|
2018-02-19 07:53:03 +00:00
|
|
|
>>> exc = None
|
2017-11-18 03:35:40 +00:00
|
|
|
>>> try:
|
|
|
|
... b.putall([(2, 1), (2, 3)], on_dup_key=RAISE, on_dup_val=OVERWRITE)
|
2018-02-19 07:53:03 +00:00
|
|
|
... except DuplicationError as e:
|
|
|
|
... exc = e
|
|
|
|
>>> exc is not None
|
|
|
|
True
|
2017-11-18 03:35:40 +00:00
|
|
|
>>> len(b)
|
|
|
|
1
|
2018-02-27 13:09:57 +00:00
|
|
|
|
2017-11-18 03:35:40 +00:00
|
|
|
>>> b.forceupdate([(0, 1), (2, 3), (0, 3)])
|
2018-02-19 07:53:03 +00:00
|
|
|
>>> b
|
|
|
|
OrderedBidict([(0, 3)])
|