|
3 | 3 | import shutil
|
4 | 4 | import tempfile
|
5 | 5 | import unittest
|
| 6 | +import fnmatch |
6 | 7 | from typing import List, Optional, Set, Tuple
|
7 | 8 |
|
8 | 9 | from mypy.find_sources import InvalidSourceList, SourceFinder, create_source_list
|
@@ -305,8 +306,9 @@ def test_find_sources_exclude(self) -> None:
|
305 | 306 | ("a2.b.c.d.e", "/pkg"),
|
306 | 307 | ("e", "/pkg/a1/b/c/d"),
|
307 | 308 | ]
|
308 |
| - assert find_sources(["/pkg/a1/b/f.py"], options, fscache) == [('f', '/pkg/a1/b')] |
309 |
| - assert find_sources(["/pkg/a2/b/f.py"], options, fscache) == [('a2.b.f', '/pkg')] |
| 309 | + |
| 310 | + assert find_sources(["/pkg/a1/b/f.py"], options, fscache) == [] |
| 311 | + assert find_sources(["/pkg/a2/b/f.py"], options, fscache) == [] |
310 | 312 |
|
311 | 313 | # directory name
|
312 | 314 | options.exclude = ["/a1/"]
|
@@ -377,3 +379,51 @@ def test_find_sources_exclude(self) -> None:
|
377 | 379 | }
|
378 | 380 | fscache = FakeFSCache(files)
|
379 | 381 | assert len(find_sources(["."], options, fscache)) == len(files)
|
| 382 | + |
| 383 | + def test_find_sources_exclude_e2e(self) -> None: |
| 384 | + files_config = "/pkg/*, /src/test/" |
| 385 | + |
| 386 | + files = { |
| 387 | + "/pkg/sample.json", |
| 388 | + "/pkg/test.json", |
| 389 | + "/pkg/a1/__init__.py", |
| 390 | + "/pkg/a1/f.py", |
| 391 | + "/pkg/a1/v.py", |
| 392 | + "/pkg/a2/__init__.py", |
| 393 | + "/pkg/a2/b.py", |
| 394 | + "/pkg/a2/a.py", |
| 395 | + "/src/test/a.py", |
| 396 | + "/src/test/b.py", |
| 397 | + "/src/test/a/a.py", |
| 398 | + } |
| 399 | + |
| 400 | + def split_and_match_files(files: Set[str], paths: List[str]) -> List[str]: |
| 401 | + # mock split_and_match_files_list config_parser.py |
| 402 | + expanded_paths = [] |
| 403 | + |
| 404 | + for p in paths: |
| 405 | + p = p.strip() |
| 406 | + # glob uses fnmatch underneath |
| 407 | + matching = fnmatch.filter(files, p) |
| 408 | + print("PATH", p) |
| 409 | + if matching: |
| 410 | + expanded_paths.extend(matching) |
| 411 | + else: |
| 412 | + expanded_paths.append(p) |
| 413 | + return expanded_paths |
| 414 | + |
| 415 | + all_files = split_and_match_files(files, files_config.split(',')) |
| 416 | + del split_and_match_files |
| 417 | + options = Options() |
| 418 | + fscache = FakeFSCache(files) |
| 419 | + |
| 420 | + assert find_sources(all_files, options, fscache) == [ |
| 421 | + ('a', '/src/test/a'), |
| 422 | + ('a1', '/pkg'), |
| 423 | + ('a1.f', '/pkg'), |
| 424 | + ('a1.v', '/pkg'), |
| 425 | + ('a2', '/pkg'), |
| 426 | + ('a2.a', '/pkg'), |
| 427 | + ('a2.b', '/pkg'), |
| 428 | + ('b', '/src/test') |
| 429 | + ] |
0 commit comments