@@ -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,23 +123,19 @@ 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
)
119
136
@set_config (ignore_paths = "" )
120
137
def test_expand_modules (
121
- self , files_or_modules : list [str ], expected : list [ ModuleDescriptionDict ]
138
+ self , files_or_modules : list [str ], expected : dict [ str , ModuleDescriptionDict ]
122
139
) -> None :
123
140
"""Test expand_modules with the default value of ignore-paths."""
124
141
ignore_list : list [str ] = []
@@ -129,25 +146,54 @@ def test_expand_modules(
129
146
ignore_list_re ,
130
147
self .linter .config .ignore_paths ,
131
148
)
132
- modules .sort (key = lambda d : d ["name" ])
133
149
assert modules == expected
134
150
assert not errors
135
151
136
152
@pytest .mark .parametrize (
137
153
"files_or_modules,expected" ,
138
154
[
139
- ([__file__ ], []),
155
+ ([__file__ , __file__ ], {this_file ["path" ]: this_file }),
156
+ (
157
+ [EXPAND_MODULES , str (Path (__file__ ).parent ), EXPAND_MODULES ],
158
+ {
159
+ module ["path" ]: module # pylint: disable=unsubscriptable-object
160
+ for module in _list_expected_package_modules (deduplicating = True )
161
+ },
162
+ ),
163
+ ],
164
+ )
165
+ @set_config (ignore_paths = "" )
166
+ def test_expand_modules_deduplication (
167
+ self , files_or_modules : list [str ], expected : dict [str , ModuleDescriptionDict ]
168
+ ) -> None :
169
+ """Test expand_modules deduplication."""
170
+ ignore_list : list [str ] = []
171
+ ignore_list_re : list [re .Pattern [str ]] = []
172
+ modules , errors = expand_modules (
173
+ files_or_modules ,
174
+ ignore_list ,
175
+ ignore_list_re ,
176
+ self .linter .config .ignore_paths ,
177
+ )
178
+ assert modules == expected
179
+ assert not errors
180
+
181
+ @pytest .mark .parametrize (
182
+ "files_or_modules,expected" ,
183
+ [
184
+ ([__file__ ], {}),
140
185
(
141
186
[str (Path (__file__ ).parent )],
142
- [
143
- init_of_package ,
144
- ],
187
+ {
188
+ module ["path" ]: module # pylint: disable=unsubscriptable-object
189
+ for module in (init_of_package ,)
190
+ },
145
191
),
146
192
],
147
193
)
148
194
@set_config (ignore_paths = ".*/lint/.*" )
149
195
def test_expand_modules_with_ignore (
150
- self , files_or_modules : list [str ], expected : list [ ModuleDescriptionDict ]
196
+ self , files_or_modules : list [str ], expected : dict [ str , ModuleDescriptionDict ]
151
197
) -> None :
152
198
"""Test expand_modules with a non-default value of ignore-paths."""
153
199
ignore_list : list [str ] = []
@@ -158,6 +204,5 @@ def test_expand_modules_with_ignore(
158
204
ignore_list_re ,
159
205
self .linter .config .ignore_paths ,
160
206
)
161
- modules .sort (key = lambda d : d ["name" ])
162
207
assert modules == expected
163
208
assert not errors
0 commit comments