2015-12-21 03:05:20 +00:00
|
|
|
Test script for bidict.loosebidict::
|
|
|
|
|
|
|
|
>>> from bidict import loosebidict
|
|
|
|
|
|
|
|
Initializing with different keys mapping to the same value succeeds::
|
|
|
|
|
|
|
|
>>> loosebidict([(1, 1), (2, 1)])
|
|
|
|
loosebidict({2: 1})
|
|
|
|
|
|
|
|
Adding a new key associated with an existing value succeeds::
|
|
|
|
|
|
|
|
>>> b = loosebidict({1: 1})
|
|
|
|
>>> b[2] = 1
|
|
|
|
>>> b
|
|
|
|
loosebidict({2: 1})
|
|
|
|
>>> b.update({3: 1})
|
|
|
|
>>> b
|
|
|
|
loosebidict({3: 1})
|
|
|
|
|
2016-06-28 04:05:22 +00:00
|
|
|
Using ``update`` with an existing key successfully overwrites::
|
2015-12-21 03:05:20 +00:00
|
|
|
|
2016-06-28 04:05:22 +00:00
|
|
|
>>> b.update({3: 2})
|
2015-12-21 03:05:20 +00:00
|
|
|
>>> b
|
2016-06-28 04:05:22 +00:00
|
|
|
loosebidict({3: 2})
|
|
|
|
|
|
|
|
Subclassing works as expected::
|
|
|
|
|
|
|
|
>>> class myloosebidict(loosebidict): pass
|
|
|
|
>>> b = myloosebidict()
|
|
|
|
>>> b[2] = 4
|
2015-12-21 03:05:20 +00:00
|
|
|
>>> b
|
2016-06-28 04:05:22 +00:00
|
|
|
myloosebidict({2: 4})
|