MCPcopy Create free account
hub / github.com/PyCQA/flake8 / test_importlib_plugins

Function test_importlib_plugins

tests/unit/plugins/finder_test.py:218–336  ·  view source on GitHub ↗

Ensure we can load plugins from importlib.metadata.

(
    tmp_path,
    flake8_dist,
    flake8_foo_dist,
    mock_distribution,
    caplog,
)

Source from the content-addressed store, hash-verified

216
217
218def test_importlib_plugins(
219 tmp_path,
220 flake8_dist,
221 flake8_foo_dist,
222 mock_distribution,
223 caplog,
224):
225 """Ensure we can load plugins from importlib.metadata."""
226
227 # make sure flake8-colors is skipped
228 flake8_colors_metadata = """\
229Metadata-Version: 2.1
230Name: flake8-colors
231Version: 1.2.3
232"""
233 flake8_colors_eps = """\
234[flake8.extension]
235flake8-colors = flake8_colors:ColorFormatter
236"""
237 flake8_colors_d = tmp_path.joinpath("flake8_colors.dist-info")
238 flake8_colors_d.mkdir()
239 flake8_colors_d.joinpath("METADATA").write_text(flake8_colors_metadata)
240 flake8_colors_d.joinpath("entry_points.txt").write_text(flake8_colors_eps)
241 flake8_colors_dist = importlib.metadata.PathDistribution(flake8_colors_d)
242
243 unrelated_metadata = """\
244Metadata-Version: 2.1
245Name: unrelated
246Version: 4.5.6
247"""
248 unrelated_eps = """\
249[console_scripts]
250unrelated = unrelated:main
251"""
252 unrelated_d = tmp_path.joinpath("unrelated.dist-info")
253 unrelated_d.mkdir()
254 unrelated_d.joinpath("METADATA").write_text(unrelated_metadata)
255 unrelated_d.joinpath("entry_points.txt").write_text(unrelated_eps)
256 unrelated_dist = importlib.metadata.PathDistribution(unrelated_d)
257
258 with mock.patch.object(
259 importlib.metadata,
260 "distributions",
261 return_value=[
262 flake8_dist,
263 flake8_colors_dist,
264 flake8_foo_dist,
265 unrelated_dist,
266 ],
267 ):
268 ret = set(finder._find_importlib_plugins())
269
270 assert ret == {
271 finder.Plugin(
272 "flake8-foo",
273 "1.2.3",
274 importlib.metadata.EntryPoint(
275 "Q", "flake8_foo:Plugin", "flake8.extension",

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected