(self)
| 262 | assert find_sources_in_dir(finder, "/") == [("pkg.a", "/a"), ("pkg.b", "/b")] |
| 263 | |
| 264 | def test_find_sources_exclude(self) -> None: |
| 265 | options = Options() |
| 266 | options.namespace_packages = True |
| 267 | |
| 268 | # default |
| 269 | for excluded_dir in ["site-packages", ".whatever", "node_modules", ".x/.z"]: |
| 270 | fscache = FakeFSCache({"/dir/a.py", f"/dir/venv/{excluded_dir}/b.py"}) |
| 271 | assert find_sources(["/"], options, fscache) == [("a", "/dir")] |
| 272 | with pytest.raises(InvalidSourceList): |
| 273 | find_sources(["/dir/venv/"], options, fscache) |
| 274 | assert find_sources([f"/dir/venv/{excluded_dir}"], options, fscache) == [ |
| 275 | ("b", f"/dir/venv/{excluded_dir}") |
| 276 | ] |
| 277 | assert find_sources([f"/dir/venv/{excluded_dir}/b.py"], options, fscache) == [ |
| 278 | ("b", f"/dir/venv/{excluded_dir}") |
| 279 | ] |
| 280 | |
| 281 | files = { |
| 282 | "/pkg/a1/b/c/d/e.py", |
| 283 | "/pkg/a1/b/f.py", |
| 284 | "/pkg/a2/__init__.py", |
| 285 | "/pkg/a2/b/c/d/e.py", |
| 286 | "/pkg/a2/b/f.py", |
| 287 | } |
| 288 | |
| 289 | # file name |
| 290 | options.exclude = [r"/f\.py$"] |
| 291 | fscache = FakeFSCache(files) |
| 292 | assert find_sources(["/"], options, fscache) == [ |
| 293 | ("a2", "/pkg"), |
| 294 | ("a2.b.c.d.e", "/pkg"), |
| 295 | ("e", "/pkg/a1/b/c/d"), |
| 296 | ] |
| 297 | assert find_sources(["/pkg/a1/b/f.py"], options, fscache) == [("f", "/pkg/a1/b")] |
| 298 | assert find_sources(["/pkg/a2/b/f.py"], options, fscache) == [("a2.b.f", "/pkg")] |
| 299 | |
| 300 | # directory name |
| 301 | options.exclude = ["/a1/"] |
| 302 | fscache = FakeFSCache(files) |
| 303 | assert find_sources(["/"], options, fscache) == [ |
| 304 | ("a2", "/pkg"), |
| 305 | ("a2.b.c.d.e", "/pkg"), |
| 306 | ("a2.b.f", "/pkg"), |
| 307 | ] |
| 308 | with pytest.raises(InvalidSourceList): |
| 309 | find_sources(["/pkg/a1"], options, fscache) |
| 310 | with pytest.raises(InvalidSourceList): |
| 311 | find_sources(["/pkg/a1/"], options, fscache) |
| 312 | with pytest.raises(InvalidSourceList): |
| 313 | find_sources(["/pkg/a1/b"], options, fscache) |
| 314 | |
| 315 | options.exclude = ["/a1/$"] |
| 316 | assert find_sources(["/pkg/a1"], options, fscache) == [ |
| 317 | ("e", "/pkg/a1/b/c/d"), |
| 318 | ("f", "/pkg/a1/b"), |
| 319 | ] |
| 320 | |
| 321 | # paths |
nothing calls this directly
no test coverage detected