Skip to content

Commit 4be607e

Browse files
authored
Fixes CI (#689)
* Fixes CI * Fixes CI
1 parent 4058c80 commit 4be607e

File tree

5 files changed

+22
-29
lines changed

5 files changed

+22
-29
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ See [0Ver](https://0ver.org/).
7272
- Adds `collect_trace` helper function for better development experience
7373
- Adds `hypothesis` intergration and pre-defined "monad laws as values"
7474

75+
- Adds `assert_equal` method to our `pytest` plugin
76+
7577
### Bugfixes
7678

7779
- **Breaking**: fixes serious typing issue and changes how `flow` works

docs/pages/contrib/pytest_plugins.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ This is how it works internally:
109109
It does not affect production code.
110110

111111

112-
has_trace
113-
~~~~~~~~~
112+
assert_trace
113+
~~~~~~~~~~~~
114114

115115
Sometimes we have to know if a container is created correctly in a specific
116116
point of our flow.
117117

118-
``has_trace`` helps us to check exactly this by identifying when a container is
118+
``assert_trace`` helps us to check exactly this by
119+
identifying when a container is
119120
created and looking for the desired function.
120121

121122
.. code:: python
@@ -131,13 +132,13 @@ created and looking for the desired function.
131132
>>> def test_if_failure_is_created_at_convert_function(
132133
... returns: ReturnsAsserts,
133134
... ):
134-
... with returns.has_trace(Failure, desired_function):
135+
... with returns.assert_trace(Failure, desired_function):
135136
... Success('not a number').bind(desired_function)
136137
137138
>>> def test_if_success_is_created_at_convert_function(
138139
... returns: ReturnsAsserts,
139140
... ):
140-
... with returns.has_trace(Success, desired_function):
141+
... with returns.assert_trace(Success, desired_function):
141142
... Success('42').bind(desired_function)
142143
143144
>>> # We only run these tests manually, because it is a doc example:

returns/contrib/pytest/plugin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing_extensions import Final, final
1010

1111
if TYPE_CHECKING:
12-
from returns.interfaces.failable import FailableN
1312
from returns.interfaces.specific.result import ResultLikeN
1413

1514
_ERROR_FIELD: Final = '_error_handled'
@@ -45,12 +44,12 @@ def assert_equal(
4544
from returns.primitives.asserts import assert_equal
4645
assert_equal(first, second, deps=deps, backend=backend)
4746

48-
def is_error_handled(self, container: 'FailableN') -> bool:
47+
def is_error_handled(self, container) -> bool:
4948
"""Ensures that container has its error handled in the end."""
5049
return bool(getattr(container, _ERROR_FIELD, False))
5150

5251
@contextmanager
53-
def has_trace(
52+
def assert_trace(
5453
self,
5554
trace_type: _ReturnsResultType,
5655
function_to_search: _FunctionType,

tests/test_contrib/test_pytest/test_plugin_has_trace.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def _create_container_function_intermediate(container_type, container_value):
2121
IOSuccess,
2222
IOFailure,
2323
])
24-
def test_has_trace1(container_type, returns: ReturnsAsserts):
24+
def test_assert_trace1(container_type, returns: ReturnsAsserts):
2525
"""Test if our plugin will identify the container creation correctly."""
26-
with returns.has_trace(container_type, _create_container_function):
26+
with returns.assert_trace(container_type, _create_container_function):
2727
_create_container_function(container_type, 1) # type: ignore
2828

2929

@@ -33,9 +33,9 @@ def test_has_trace1(container_type, returns: ReturnsAsserts):
3333
IOSuccess,
3434
IOFailure,
3535
])
36-
def test_has_trace2(container_type, returns: ReturnsAsserts):
36+
def test_assert_trace2(container_type, returns: ReturnsAsserts):
3737
"""Test if our plugin will identify the container creation correctly."""
38-
with returns.has_trace(container_type, _create_container_function):
38+
with returns.assert_trace(container_type, _create_container_function):
3939
_create_container_function_intermediate( # type: ignore
4040
container_type, 1,
4141
)
@@ -47,10 +47,12 @@ def test_has_trace2(container_type, returns: ReturnsAsserts):
4747
(IOSuccess, IOFailure),
4848
(IOFailure, IOSuccess),
4949
])
50-
def test_failed_has_trace1(desired_type, wrong_type, returns: ReturnsAsserts):
50+
def test_failed_assert_trace1(
51+
desired_type, wrong_type, returns: ReturnsAsserts,
52+
):
5153
"""Test if our plugin will identify the conainter was not created."""
5254
with pytest.raises(pytest.fail.Exception): # noqa: PT012
53-
with returns.has_trace(desired_type, _create_container_function):
55+
with returns.assert_trace(desired_type, _create_container_function):
5456
_create_container_function(wrong_type, 1) # type: ignore
5557

5658

@@ -60,10 +62,12 @@ def test_failed_has_trace1(desired_type, wrong_type, returns: ReturnsAsserts):
6062
(IOSuccess, IOFailure),
6163
(IOFailure, IOSuccess),
6264
])
63-
def test_failed_has_trace2(desired_type, wrong_type, returns: ReturnsAsserts):
65+
def test_failed_assert_trace2(
66+
desired_type, wrong_type, returns: ReturnsAsserts,
67+
):
6468
"""Test if our plugin will identify the conainter was not created."""
6569
with pytest.raises(pytest.fail.Exception): # noqa: PT012
66-
with returns.has_trace(desired_type, _create_container_function):
70+
with returns.assert_trace(desired_type, _create_container_function):
6771
_create_container_function_intermediate( # type: ignore
6872
wrong_type, 1,
6973
)

typesafety/test_contrib/test_pytest/test_returns_asserts.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)