Skip to content

Commit

Permalink
Add test to ensure toolz.curried.operator is properly curried
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw committed Jul 5, 2022
1 parent 77c044e commit 7880c57
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions toolz/tests/test_curried.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ def test_module_name():
assert toolz.curried.__name__ == 'toolz.curried'


def should_curry(func):
if not callable(func) or isinstance(func, toolz.curry):
return False
nargs = toolz.functoolz.num_required_args(func)
if nargs is None or nargs > 1:
return True
return nargs == 1 and toolz.functoolz.has_keywords(func)


def test_curried_operator():
import operator

for k, v in vars(cop).items():
if not callable(v):
continue
Expand All @@ -60,6 +71,7 @@ def test_curried_operator():
raise AssertionError(
'toolz.curried.operator.%s is not curried!' % k,
)
assert should_curry(getattr(operator, k)) == isinstance(v, toolz.curry), k

# Make sure this isn't totally empty.
assert len(set(vars(cop)) & {'add', 'sub', 'mul'}) == 3
Expand All @@ -69,14 +81,6 @@ def test_curried_namespace():
exceptions = import_module('toolz.curried.exceptions')
namespace = {}

def should_curry(func):
if not callable(func) or isinstance(func, toolz.curry):
return False
nargs = toolz.functoolz.num_required_args(func)
if nargs is None or nargs > 1:
return True
return nargs == 1 and toolz.functoolz.has_keywords(func)


def curry_namespace(ns):
return {
Expand Down

0 comments on commit 7880c57

Please sign in to comment.