Skip to content

Commit 0c6aaff

Browse files
authored
Test that Fold methods are recursion safe (#677)
* Test that fold methods are recursion safe * Fixes grammar in fold docstrings * Fixes docs for fold, refactors tests
1 parent 36c3cc6 commit 0c6aaff

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

returns/iterables.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AbstractFold(object):
2525
.. rubric:: Implementation
2626
2727
``AbstractFold`` and ``Fold`` types are special.
28-
They have duoble definition for all method: public and protected ones.
28+
They have double definition for each method: public and protected ones.
2929
Why?
3030
3131
Because you cannot override ``@kinded`` method due to a ``mypy`` bug.
@@ -36,8 +36,8 @@ class AbstractFold(object):
3636
3737
We have chosen the second way! Here's how it works:
3838
39-
1. Public methods are ``@kinded`` for better typing and cannot be overriden
40-
2. Protected methods are unkinded and can be overriden in subtyping
39+
1. Public methods are ``@kinded`` for better typing and cannot be overridden
40+
2. Protected methods are unkinded and can be overridden in subtyping
4141
4242
Now, if you need to make a change into our implementation,
4343
then you can subclass ``Fold`` or ``AbstractFold`` and then
@@ -179,7 +179,7 @@ def collect_all(
179179
not just any ``ApplicativeN`` like :meth:`~AbstractFold.collect`.
180180
181181
Strategy to extract all successful values
182-
even if there are failued values.
182+
even if there are failed values.
183183
184184
If there's at least one successful value
185185
and any amount of failed values,

tests/test_iterables/test_fold/test_collect.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from typing import Iterable, List, Sequence, Tuple
23

34
import pytest
@@ -200,3 +201,11 @@ async def test_fold_collect_future_result(subtests):
200201
assert await Fold.collect(
201202
iterable, sequence.from_value(()),
202203
) == await sequence
204+
205+
206+
def test_fold_collect_recursion_limit():
207+
"""Ensures that ``.collect`` method is recurion safe."""
208+
limit = sys.getrecursionlimit() + 1
209+
iterable = (IO(1) for _ in range(limit))
210+
expected = IO((1,) * limit)
211+
assert Fold.collect(iterable, IO(())) == expected

tests/test_iterables/test_fold/test_collect_all.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from typing import Iterable, List, Sequence, Tuple
23

34
import pytest
@@ -158,3 +159,11 @@ async def test_collect_all_future_result(subtests):
158159
assert await Fold.collect_all(
159160
iterable, sequence.from_value(()),
160161
) == await sequence
162+
163+
164+
def test_fold_collect_recursion_limit():
165+
"""Ensures that ``.collect_all`` method is recurion safe."""
166+
limit = sys.getrecursionlimit() + 1
167+
iterable = (Success(1) for _ in range(limit))
168+
expected = Success((1,) * limit)
169+
assert Fold.collect_all(iterable, Success(())) == expected

tests/test_iterables/test_fold/test_loop.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from typing import Iterable, List, Tuple
23

34
import pytest
@@ -216,3 +217,10 @@ async def test_fold_collect_future_result(subtests):
216217
assert await Fold.loop(
217218
iterable, sequence.from_value(10), _sum_two,
218219
) == await sequence
220+
221+
222+
def test_fold_loop_recursion_limit():
223+
"""Ensures that ``.loop`` method is recurion safe."""
224+
limit = sys.getrecursionlimit() + 1
225+
iterable = (IO(1) for _ in range(limit))
226+
assert Fold.loop(iterable, IO(0), _sum_two) == IO(limit)

0 commit comments

Comments
 (0)