Ensure we can load plugins from importlib.metadata.
(
tmp_path,
flake8_dist,
flake8_foo_dist,
mock_distribution,
caplog,
)
| 216 | |
| 217 | |
| 218 | def 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 = """\ |
| 229 | Metadata-Version: 2.1 |
| 230 | Name: flake8-colors |
| 231 | Version: 1.2.3 |
| 232 | """ |
| 233 | flake8_colors_eps = """\ |
| 234 | [flake8.extension] |
| 235 | flake8-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 = """\ |
| 244 | Metadata-Version: 2.1 |
| 245 | Name: unrelated |
| 246 | Version: 4.5.6 |
| 247 | """ |
| 248 | unrelated_eps = """\ |
| 249 | [console_scripts] |
| 250 | unrelated = 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", |
nothing calls this directly
no outgoing calls
no test coverage detected