Skip to content

Commit

Permalink
🚀 version 0.0.4 - fix: expand absolute paths correctly when configuri…
Browse files Browse the repository at this point in the history
…ng matchers
  • Loading branch information
davidjrice committed Oct 20, 2023
1 parent 4bfa20d commit b3b7724
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build:
@hatch build .

install:
@pip3 install autotest*.tar.gz
@pip install autopytest*.tar.gz

test: # Run tests
@python3 setup.py pytest
17 changes: 12 additions & 5 deletions autopytest/autotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@

class Source:

def __init__(self, directory) -> None:
def __init__(self, directory, path) -> None:
self.directory = directory
self.path = path

@property
def dir(self) -> Path:
return Path(self.path).absolute().joinpath(self.directory)

@property
def pattern(self) -> str:
return r"^\./" + re.escape(self.directory) + r".+\.py$"
return r"^" + re.escape(self.dir.as_posix()) + r".+\.py$"


class Autotest(FileSystemEventHandler):
Expand All @@ -33,7 +38,9 @@ def __init__(self, path:str):

self.sources = []
for directory in self.source_directories:
self.sources.append(Source(directory=directory))
source = Source(directory=directory, path=path)
self.sources.append(source)
log.info(f"{source.directory} {source.pattern}")
self.test_pattern = re.escape(self.test_directory) + r".+\.py$"


Expand All @@ -59,8 +66,8 @@ def on_modified(self, event: FileSystemEvent) -> None:
path = Path(event.src_path)
test_path_components = ["tests"]

for component in path.parts:
if not self.include_source_directories_in_test_path and component == source.directory:
for component in path.relative_to(source.dir).parts:
if not self.include_source_dir_in_test_path and component == source.directory:
continue
elif re.search(r".py", component):
test_path_components.append(f"test_{component}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "autopytest"
version = "0.0.3"
version = "0.0.4"
description = "Autotest python code"
authors = [
{ name = "David Rice", email = "[email protected]" },
Expand Down

0 comments on commit b3b7724

Please sign in to comment.