Skip to content

Commit

Permalink
Merge pull request #239 from musicinmybrain/map-doctest-order
Browse files Browse the repository at this point in the history
Make pyrsistent._pmap doctests order-insensitive
  • Loading branch information
tobgu committed Jan 14, 2022
2 parents 09173bf + e09ed69 commit 564905c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 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)
3 changes: 0 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ changedir = .
commands = python tests/memory_profiling.py

[testenv:doctest38]
# Need to disable the random hashing or all docs printing a map with more than
# one item in it will be flaky.
setenv = PYTHONHASHSEED=0
basepython = python3.8
deps = pytest
changedir = .
Expand Down

0 comments on commit 564905c

Please sign in to comment.