@@ -45,6 +45,14 @@ def test__is_in_ignore_list_re_match() -> None:
4545 "path" : EXPAND_MODULES ,
4646}
4747
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+
4856unittest_lint = {
4957 "basename" : "lint" ,
5058 "basepath" : INIT_PATH ,
@@ -77,7 +85,6 @@ def test__is_in_ignore_list_re_match() -> None:
7785 "path" : str (TEST_DIRECTORY / "lint/test_caching.py" ),
7886}
7987
80-
8188init_of_package = {
8289 "basename" : "lint" ,
8390 "basepath" : INIT_PATH ,
@@ -87,6 +94,20 @@ def test__is_in_ignore_list_re_match() -> None:
8794}
8895
8996
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+
90111class TestExpandModules (CheckerTestCase ):
91112 """Test the expand_modules function while allowing options to be set."""
92113
@@ -102,23 +123,19 @@ class Checker(BaseChecker):
102123 @pytest .mark .parametrize (
103124 "files_or_modules,expected" ,
104125 [
105- ([__file__ ], [ this_file ] ),
126+ ([__file__ ], { this_file [ "path" ]: this_file } ),
106127 (
107128 [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+ },
116133 ),
117134 ],
118135 )
119136 @set_config (ignore_paths = "" )
120137 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 ]
122139 ) -> None :
123140 """Test expand_modules with the default value of ignore-paths."""
124141 ignore_list : list [str ] = []
@@ -129,25 +146,54 @@ def test_expand_modules(
129146 ignore_list_re ,
130147 self .linter .config .ignore_paths ,
131148 )
132- modules .sort (key = lambda d : d ["name" ])
133149 assert modules == expected
134150 assert not errors
135151
136152 @pytest .mark .parametrize (
137153 "files_or_modules,expected" ,
138154 [
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__ ], {}),
140185 (
141186 [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+ },
145191 ),
146192 ],
147193 )
148194 @set_config (ignore_paths = ".*/lint/.*" )
149195 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 ]
151197 ) -> None :
152198 """Test expand_modules with a non-default value of ignore-paths."""
153199 ignore_list : list [str ] = []
@@ -158,6 +204,5 @@ def test_expand_modules_with_ignore(
158204 ignore_list_re ,
159205 self .linter .config .ignore_paths ,
160206 )
161- modules .sort (key = lambda d : d ["name" ])
162207 assert modules == expected
163208 assert not errors
0 commit comments