Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/eth_utils.curried.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
eth\_utils.curried package
==========================

Submodules
----------

eth\_utils.curried.toolz module
-------------------------------

.. automodule:: eth_utils.curried.toolz
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

Expand Down
19 changes: 19 additions & 0 deletions eth_utils/curried/toolz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Compatibility wrappers for the curried toolz API.
"""

try:
from cytoolz import (
curried as _curried_toolz,
)
except ImportError:
from toolz import (
curried as _curried_toolz,
)


globals().update(
{name: value for name, value in vars(_curried_toolz).items() if "__" not in name}
)

del _curried_toolz
2 changes: 2 additions & 0 deletions newsfragments/136.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added the ``eth_utils.curried.toolz`` compatibility module so curried toolz
helpers can be imported through ``eth-utils``.
52 changes: 52 additions & 0 deletions tests/core/curried-utils/test_curried_toolz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
try:
from cytoolz import (
curried as upstream_curried_toolz,
)
except ImportError:
from toolz import curried as upstream_curried_toolz

from eth_utils.curried import (
toolz as imported_toolz_module,
)
import eth_utils.curried.toolz


def test_curried_toolz_module_is_importable_from_package():
assert imported_toolz_module is eth_utils.curried.toolz


def test_curried_toolz_namespace_matches_upstream():
expected = {
name: value
for name, value in vars(upstream_curried_toolz).items()
if "__" not in name
}
actual = {
name: value
for name, value in vars(eth_utils.curried.toolz).items()
if "__" not in name
}

assert actual == expected


def test_curried_toolz_dicttoolz_smoke_test():
assert eth_utils.curried.toolz.get("count")({"count": 3}) == 3


def test_curried_toolz_functoolz_smoke_test():
hexint = eth_utils.curried.toolz.compose(hex, int)

assert hexint("10") == "0xa"


def test_curried_toolz_itertoolz_smoke_test():
drop2 = eth_utils.curried.toolz.drop(2)

assert list(drop2([4, 3, 2, 1])) == [2, 1]


def test_curried_toolz_recipe_smoke_test():
windows = eth_utils.curried.toolz.sliding_window(2)([1, 2, 3, 4])

assert tuple(windows) == ((1, 2), (2, 3), (3, 4))