@@ -45,6 +45,14 @@ def test__is_in_ignore_list_re_match() -> None:
45
45
"path" : EXPAND_MODULES ,
46
46
}
47
47
48
+ this_file_from_init_deduplicated = {
49
+ "basename" : "lint" ,
50
+ "basepath" : INIT_PATH ,
51
+ "isarg" : True ,
52
+ "name" : "lint.unittest_expand_modules" ,
53
+ "path" : EXPAND_MODULES ,
54
+ }
55
+
48
56
unittest_lint = {
49
57
"basename" : "lint" ,
50
58
"basepath" : INIT_PATH ,
@@ -77,7 +85,6 @@ def test__is_in_ignore_list_re_match() -> None:
77
85
"path" : str (TEST_DIRECTORY / "lint/test_caching.py" ),
78
86
}
79
87
80
-
81
88
init_of_package = {
82
89
"basename" : "lint" ,
83
90
"basepath" : INIT_PATH ,
@@ -87,6 +94,20 @@ def test__is_in_ignore_list_re_match() -> None:
87
94
}
88
95
89
96
97
+ def _list_expected_package_modules (
98
+ deduplicating : bool = False ,
99
+ ) -> tuple [dict [str , object ], ...]:
100
+ """Generates reusable list of modules for our package."""
101
+ return (
102
+ init_of_package ,
103
+ test_caching ,
104
+ test_pylinter ,
105
+ test_utils ,
106
+ this_file_from_init_deduplicated if deduplicating else this_file_from_init ,
107
+ unittest_lint ,
108
+ )
109
+
110
+
90
111
class TestExpandModules (CheckerTestCase ):
91
112
"""Test the expand_modules function while allowing options to be set."""
92
113
@@ -102,17 +123,13 @@ class Checker(BaseChecker):
102
123
@pytest .mark .parametrize (
103
124
"files_or_modules,expected" ,
104
125
[
105
- ([__file__ ], [ this_file ] ),
126
+ ([__file__ ], { this_file [ "path" ]: this_file } ),
106
127
(
107
128
[str (Path (__file__ ).parent )],
108
- [
109
- init_of_package ,
110
- test_caching ,
111
- test_pylinter ,
112
- test_utils ,
113
- this_file_from_init ,
114
- unittest_lint ,
115
- ],
129
+ {
130
+ module ["path" ]: module # pylint: disable=unsubscriptable-object
131
+ for module in _list_expected_package_modules ()
132
+ },
116
133
),
117
134
],
118
135
)
@@ -126,19 +143,48 @@ def test_expand_modules(self, files_or_modules, expected):
126
143
ignore_list_re ,
127
144
self .linter .config .ignore_paths ,
128
145
)
129
- modules .sort (key = lambda d : d ["name" ])
130
146
assert modules == expected
131
147
assert not errors
132
148
133
149
@pytest .mark .parametrize (
134
150
"files_or_modules,expected" ,
135
151
[
136
- ([__file__ ], []),
152
+ ([__file__ , __file__ ], {this_file ["path" ]: this_file }),
153
+ (
154
+ [EXPAND_MODULES , str (Path (__file__ ).parent ), EXPAND_MODULES ],
155
+ {
156
+ module ["path" ]: module # pylint: disable=unsubscriptable-object
157
+ for module in _list_expected_package_modules (deduplicating = True )
158
+ },
159
+ ),
160
+ ],
161
+ )
162
+ @set_config (ignore_paths = "" )
163
+ def test_expand_modules_deduplication (
164
+ self , files_or_modules : list [str ], expected
165
+ ) -> None :
166
+ """Test expand_modules deduplication."""
167
+ ignore_list : list [str ] = []
168
+ ignore_list_re : list [re .Pattern [str ]] = []
169
+ modules , errors = expand_modules (
170
+ files_or_modules ,
171
+ ignore_list ,
172
+ ignore_list_re ,
173
+ self .linter .config .ignore_paths ,
174
+ )
175
+ assert modules == expected
176
+ assert not errors
177
+
178
+ @pytest .mark .parametrize (
179
+ "files_or_modules,expected" ,
180
+ [
181
+ ([__file__ ], {}),
137
182
(
138
183
[str (Path (__file__ ).parent )],
139
- [
140
- init_of_package ,
141
- ],
184
+ {
185
+ module ["path" ]: module # pylint: disable=unsubscriptable-object
186
+ for module in (init_of_package ,)
187
+ },
142
188
),
143
189
],
144
190
)
@@ -152,6 +198,5 @@ def test_expand_modules_with_ignore(self, files_or_modules, expected):
152
198
ignore_list_re ,
153
199
self .linter .config .ignore_paths ,
154
200
)
155
- modules .sort (key = lambda d : d ["name" ])
156
201
assert modules == expected
157
202
assert not errors
0 commit comments