| 531 | ], |
| 532 | ) |
| 533 | def test_inclexcl_patterns_from_file(tmpdir, lines, expected): |
| 534 | files = [ |
| 535 | "data", |
| 536 | "data/something00.txt", |
| 537 | "data/subdir/something01.txt", |
| 538 | "home", |
| 539 | "home/leo", |
| 540 | "home/leo/t", |
| 541 | "home/other", |
| 542 | ] |
| 543 | |
| 544 | def evaluate(filename): |
| 545 | matcher = PatternMatcher(fallback=True) |
| 546 | roots = [] |
| 547 | inclexclpatterns = [] |
| 548 | with open(filename) as f: |
| 549 | load_pattern_file(f, roots, inclexclpatterns) |
| 550 | matcher.add_inclexcl(inclexclpatterns) |
| 551 | return [path for path in files if matcher.match(path)] |
| 552 | |
| 553 | patternfile = tmpdir.join("patterns.txt") |
| 554 | |
| 555 | with patternfile.open("wt") as fh: |
| 556 | fh.write("\n".join(lines)) |
| 557 | |
| 558 | assert evaluate(str(patternfile)) == (files if expected is None else expected) |
| 559 | |
| 560 | |
| 561 | @pytest.mark.parametrize( |