Skip to content

Commit 7d6e28d

Browse files
committed
adds tests for functions that handle filtering
1 parent 46dffc3 commit 7d6e28d

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import pytest
2+
from scripts.microgenerator.generate import (
3+
_should_include_class,
4+
_should_include_method,
5+
)
6+
7+
8+
# Tests for _should_include_class
9+
@pytest.mark.parametrize(
10+
"class_name, filters, expected",
11+
[
12+
("MyClass", {}, True), # No filters
13+
(
14+
"DatasetClient",
15+
{"include_suffixes": ["Client", "Service"]},
16+
True,
17+
), # Include suffix match
18+
(
19+
"MyClass",
20+
{"include_suffixes": ["Client", "Service"]},
21+
False,
22+
), # Include suffix no match
23+
(
24+
"MyBase",
25+
{"exclude_suffixes": ["Base", "Util"]},
26+
False,
27+
), # Exclude suffix match
28+
(
29+
"MyClass",
30+
{"exclude_suffixes": ["Base", "Util"]},
31+
True,
32+
), # Exclude suffix no match
33+
(
34+
"DatasetClient",
35+
{"include_suffixes": ["Client"], "exclude_suffixes": ["BaseClient"]},
36+
True,
37+
), # Mix include/exclude
38+
(
39+
"BaseClient",
40+
{"include_suffixes": ["Client"], "exclude_suffixes": ["BaseClient"]},
41+
False,
42+
), # Mix include/exclude
43+
(
44+
"MyClass",
45+
{"include_suffixes": [], "exclude_suffixes": []},
46+
True,
47+
), # Empty filters
48+
],
49+
)
50+
def test_should_include_class(class_name, filters, expected):
51+
assert _should_include_class(class_name, filters) is expected
52+
53+
54+
# Tests for _should_include_method
55+
@pytest.mark.parametrize(
56+
"method_name, filters, expected",
57+
[
58+
("my_method", {}, True), # No filters
59+
(
60+
"get_dataset",
61+
{"include_prefixes": ["get_", "list_"]},
62+
True,
63+
), # Include prefix match
64+
(
65+
"list_jobs",
66+
{"include_prefixes": ["get_", "list_"]},
67+
True,
68+
), # Include prefix match
69+
(
70+
"create_dataset",
71+
{"include_prefixes": ["get_", "list_"]},
72+
False,
73+
), # Include prefix no match
74+
(
75+
"_private_method",
76+
{"exclude_prefixes": ["_", "internal_"]},
77+
False,
78+
), # Exclude prefix match
79+
(
80+
"internal_helper",
81+
{"exclude_prefixes": ["_", "internal_"]},
82+
False,
83+
), # Exclude prefix match
84+
(
85+
"get_dataset",
86+
{"exclude_prefixes": ["_", "internal_"]},
87+
True,
88+
), # Exclude prefix no match
89+
(
90+
"get_dataset",
91+
{"include_prefixes": ["get_"], "exclude_prefixes": ["get_internal_"]},
92+
True,
93+
), # Mix include/exclude
94+
(
95+
"get_internal_status",
96+
{"include_prefixes": ["get_"], "exclude_prefixes": ["get_internal_"]},
97+
False,
98+
), # Mix include/exclude
99+
(
100+
"list_datasets",
101+
{"include_prefixes": ["get_"], "exclude_prefixes": ["get_internal_"]},
102+
False,
103+
), # Mix include/exclude
104+
(
105+
"my_method",
106+
{"include_prefixes": [], "exclude_prefixes": []},
107+
True,
108+
), # Empty filters
109+
],
110+
)
111+
def test_should_include_method(method_name, filters, expected):
112+
assert _should_include_method(method_name, filters) is expected

0 commit comments

Comments
 (0)