Skip to content

Commit

Permalink
Make pyrsistent._pmap doctests order-insensitive
Browse files Browse the repository at this point in the history
This keeps them from failing if CPython’s hashing algorithms change,
fixing #238.
  • Loading branch information
musicinmybrain committed Jan 14, 2022
1 parent 09173bf commit 70f3f3c
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions pyrsistent/_pmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class PMap(object):
>>> m1 = m(a=1, b=3)
>>> m2 = m1.set('c', 3)
>>> m3 = m2.remove('a')
>>> m1
pmap({'b': 3, 'a': 1})
>>> m2
pmap({'c': 3, 'b': 3, 'a': 1})
>>> m3
pmap({'c': 3, 'b': 3})
>>> m1 == {'a': 1, 'b': 3}
True
>>> m2 == {'a': 1, 'b': 3, 'c': 3}
True
>>> m3 == {'b': 3, 'c': 3}
True
>>> m3['c']
3
>>> m3.c
Expand Down Expand Up @@ -171,12 +171,12 @@ def set(self, key, val):
>>> m1 = m(a=1, b=2)
>>> m2 = m1.set('a', 3)
>>> m3 = m1.set('c' ,4)
>>> m1
pmap({'b': 2, 'a': 1})
>>> m2
pmap({'b': 2, 'a': 3})
>>> m3
pmap({'c': 4, 'b': 2, 'a': 1})
>>> m1 == {'a': 1, 'b': 2}
True
>>> m2 == {'a': 3, 'b': 2}
True
>>> m3 == {'a': 1, 'b': 2, 'c': 4}
True
"""
return self.evolver().set(key, val).persistent()

Expand Down Expand Up @@ -213,8 +213,8 @@ def update(self, *maps):
maps the rightmost (last) value is inserted.
>>> m1 = m(a=1, b=2)
>>> m1.update(m(a=2, c=3), {'a': 17, 'd': 35})
pmap({'c': 3, 'b': 2, 'a': 17, 'd': 35})
>>> m1.update(m(a=2, c=3), {'a': 17, 'd': 35}) == {'a': 17, 'b': 2, 'c': 3, 'd': 35}
True
"""
return self.update_with(lambda l, r: r, *maps)

Expand All @@ -225,8 +225,8 @@ def update_with(self, update_fn, *maps):
>>> from operator import add
>>> m1 = m(a=1, b=2)
>>> m1.update_with(add, m(a=2))
pmap({'b': 2, 'a': 3})
>>> m1.update_with(add, m(a=2)) == {'a': 3, 'b': 2}
True
The reverse behaviour of the regular merge. Keep the leftmost element instead of the rightmost.
Expand Down Expand Up @@ -381,15 +381,15 @@ def evolver(self):
The underlying pmap remains the same:
>>> m1
pmap({'b': 2, 'a': 1})
>>> m1 == {'a': 1, 'b': 2}
True
The changes are kept in the evolver. An updated pmap can be created using the
persistent() function on the evolver.
>>> m2 = e.persistent()
>>> m2
pmap({'c': 3, 'b': 2})
>>> m2 == {'b': 2, 'c': 3}
True
The new pmap will share data with the original pmap in the same way that would have
been done if only using operations on the pmap.
Expand Down Expand Up @@ -442,8 +442,8 @@ def pmap(initial={}, pre_size=0):
may have a positive performance impact in the cases where you know beforehand that a large number of elements
will be inserted into the map eventually since it will reduce the number of reallocations required.
>>> pmap({'a': 13, 'b': 14})
pmap({'b': 14, 'a': 13})
>>> pmap({'a': 13, 'b': 14}) == {'a': 13, 'b': 14}
True
"""
if not initial and pre_size == 0:
return _EMPTY_PMAP
Expand All @@ -455,7 +455,7 @@ def m(**kwargs):
"""
Creates a new persistent map. Inserts all key value arguments into the newly created map.
>>> m(a=13, b=14)
pmap({'b': 14, 'a': 13})
>>> m(a=13, b=14) == {'a': 13, 'b': 14}
True
"""
return pmap(kwargs)

0 comments on commit 70f3f3c

Please sign in to comment.