Skip to content

Commit 7880c57

Browse files
committed
Add test to ensure toolz.curried.operator is properly curried
1 parent 77c044e commit 7880c57

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

toolz/tests/test_curried.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,18 @@ def test_module_name():
4141
assert toolz.curried.__name__ == 'toolz.curried'
4242

4343

44+
def should_curry(func):
45+
if not callable(func) or isinstance(func, toolz.curry):
46+
return False
47+
nargs = toolz.functoolz.num_required_args(func)
48+
if nargs is None or nargs > 1:
49+
return True
50+
return nargs == 1 and toolz.functoolz.has_keywords(func)
51+
52+
4453
def test_curried_operator():
54+
import operator
55+
4556
for k, v in vars(cop).items():
4657
if not callable(v):
4758
continue
@@ -60,6 +71,7 @@ def test_curried_operator():
6071
raise AssertionError(
6172
'toolz.curried.operator.%s is not curried!' % k,
6273
)
74+
assert should_curry(getattr(operator, k)) == isinstance(v, toolz.curry), k
6375

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

72-
def should_curry(func):
73-
if not callable(func) or isinstance(func, toolz.curry):
74-
return False
75-
nargs = toolz.functoolz.num_required_args(func)
76-
if nargs is None or nargs > 1:
77-
return True
78-
return nargs == 1 and toolz.functoolz.has_keywords(func)
79-
8084

8185
def curry_namespace(ns):
8286
return {

0 commit comments

Comments
 (0)