Skip to content

Commit

Permalink
Merge pull request #42 from peterjc/patch-1
Browse files Browse the repository at this point in the history
Resolve relative paths when adding sources, so that these are recognized.
  • Loading branch information
jaltmayerpizzorno authored Apr 2, 2024
2 parents f7eacc3 + 5c4a716 commit 3d8295b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/slipcover/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def __init__(self):
def addSource(self, source : Path):
if isinstance(source, str):
source = Path(source)
if not source.is_absolute():
source = self.cwd / source
self.sources.append(source)
self.sources.append(source.resolve())

def addOmit(self, omit):
if not omit.startswith('*'):
Expand Down
12 changes: 12 additions & 0 deletions tests/importer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_filematcher_defaults_from_root(return_to_dir):
site_packages = next(Path(p) for p in sys.path if p != '' and (Path(p) / "pip").exists())
assert not fm.matches(site_packages / 'foo.py')


def test_filematcher_source():
from pathlib import Path
cwd = str(Path.cwd())
Expand Down Expand Up @@ -94,6 +95,17 @@ def test_filematcher_source():
assert not fm.matches(site_packages / 'foo.py')


def test_filematcher_source_resolved(monkeypatch):
from pathlib import Path
monkeypatch.chdir('tests')

fm = im.FileMatcher()
fm.addSource('../src/')

p = (Path.cwd() / '..' / 'src' / 'foo.py').resolve()
assert fm.matches(p)


def test_filematcher_omit_pattern():
from pathlib import Path
cwd = str(Path.cwd())
Expand Down

0 comments on commit 3d8295b

Please sign in to comment.