Skip to content

Commit 7dd91f0

Browse files
emerybergerclaude
andcommitted
Address review comments: fix path resolution and add test
- Fix cwd resolution to use Path.cwd().resolve() to match FileMatcher behavior - Remove redundant .resolve() call on omit pattern path since cwd is already resolved - Add test_omit_with_source to verify --omit works correctly with --source Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6177af0 commit 7dd91f0

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/slipcover/slipcover.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,12 @@ def _add_unseen_source_files(self, source: List[str]):
597597
# Prepare omit patterns (same logic as FileMatcher.addOmit)
598598
omit_patterns = []
599599
if self.omit:
600-
cwd = Path.cwd()
600+
cwd = Path.cwd().resolve()
601601
for o in self.omit:
602602
if o.startswith('*'):
603603
omit_patterns.append(o)
604604
else:
605-
omit_patterns.append(str((cwd / o).resolve()))
605+
omit_patterns.append(str(cwd / o))
606606

607607
def is_omitted(filepath: Path) -> bool:
608608
if not omit_patterns:

tests/test_coverage.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,29 @@ def test_resolves_other_sources(tmp_path):
772772
assert [] == cov['files'][baz_file]['missing_branches']
773773

774774

775+
def test_omit_with_source(tmp_path):
776+
"""Test that --omit works correctly with --source (Issue #74)."""
777+
out_file = tmp_path / "out.json"
778+
779+
# Use --source tests/imported and --omit to exclude foo.py files
780+
subprocess.run([sys.executable, '-m', 'slipcover', '--json', '--out', str(out_file),
781+
'--source', 'tests/imported', '--omit', '*/foo.py', 'tests/importer.py'],
782+
check=True)
783+
with open(out_file, "r") as f:
784+
cov = json.load(f)
785+
786+
init_file = str(Path('tests') / 'imported' / '__init__.py')
787+
foo_file = str(Path('tests') / 'imported' / 'foo.py')
788+
baz_file = str(Path('tests') / 'imported' / 'subdir' / 'baz.PY')
789+
790+
# __init__.py and baz.PY should be included
791+
assert init_file in cov['files']
792+
assert baz_file in cov['files']
793+
794+
# foo.py should be omitted due to --omit '*/foo.py'
795+
assert foo_file not in cov['files']
796+
797+
775798
def check_summaries(cov):
776799
import copy
777800

0 commit comments

Comments
 (0)