This repository was archived by the owner on Mar 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenumerable_test.py
More file actions
76 lines (62 loc) · 1.81 KB
/
enumerable_test.py
File metadata and controls
76 lines (62 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import pytest
from pyby import Enumerable, EnumerableList
from .test_helpers import pass_through
@pytest.fixture
def enumerable():
return Enumerable()
@pytest.mark.parametrize(
"method_name",
[
"any",
"all",
"each",
"collect",
"collect_concat",
"compact",
"count",
"detect",
"flat_map",
"filter",
"find",
"find_all",
"first",
"include",
"inject",
"map",
"member",
"none",
"one",
"reduce",
"reject",
"select",
"take",
"to_enum",
"uniq",
],
)
def test_public_interface(enumerable, method_name):
assert enumerable.respond_to(method_name)
@pytest.mark.parametrize(
"alias, method_name",
[
("map", "collect"),
("filter", "select"),
("reduce", "inject"),
("collect_concat", "flat_map"),
("detect", "find"),
("find_all", "select"),
("member", "include"),
],
)
def test_aliases(enumerable, alias, method_name):
assert getattr(enumerable, alias) == getattr(enumerable, method_name)
def test_each_with_function_requires___each___to_be_implemented_by_a_subclass(enumerable):
with pytest.raises(NotImplementedError, match="'__each__' must be implemented by a subclass"):
enumerable.each(pass_through)
def test_each_without_a_function_requires_an_iterable_subclass_as_to_enum_is_called(enumerable):
with pytest.raises(TypeError, match="'Enumerable' object is not iterable"):
enumerable.each()
def test____into___imports_and_returns_EnumerableList(enumerable):
enumerable.__into__("each") == EnumerableList
def test____to_tuple___wraps_the_item_in_a_tuple(enumerable):
enumerable.__to_tuple__("some value") == ("some value",)