Skip to content

Commit

Permalink
updated base handling
Browse files Browse the repository at this point in the history
  • Loading branch information
smythi93 committed Jul 28, 2024
1 parent 17e5a26 commit 83277f7
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions src/sflkit/runners/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import string
import subprocess
from pathlib import Path
from typing import List, Dict, Optional, Tuple, Set
from typing import List, Dict, Optional, Tuple

from sflkit.logger import LOGGER

Expand Down Expand Up @@ -287,29 +287,17 @@ def _common_base(directory: Path, tests: List[str]) -> Path:
def _normalize_paths(
self,
tests: List[str],
bases: Optional[Set[str]] = None,
file_base: Optional[Path] = None,
directory: Optional[Path] = None,
root_dir: Optional[Path] = None,
):
result = tests
if directory:
if bases:
for base in bases:
common = self._common_base(directory, [base])
if common:
base = common / base
base = self._common_base(base, tests)
if base is not None:
result = []
for r in tests:
path, test = r.split("::", 1)
result.append(
str((base / path).relative_to(directory))
+ "::"
+ test
)
return result
base = self._common_base(directory, tests)
base = None
if file_base:
base = self._common_base(file_base, tests)
if base is None:
base = self._common_base(directory, tests)
if base is None and root_dir:
base = self._common_base(root_dir, tests)
if base is None and root_dir is not None:
Expand Down Expand Up @@ -341,27 +329,26 @@ def get_tests(
if k:
c.append("-k")
c.append(k)
bases = set()
if base:
if not files:
c.append(str(base))
root_dir = directory / base
else:
root_dir = directory
file_base = None
if files:
if isinstance(files, (str, os.PathLike)):
str_files = [str(files)]
else:
str_files = [str(f) for f in files]
common_base = self._common_base(directory, [str(files)])
common_base = self._common_base(root_dir, [str(files)])
if common_base:
bases.add(common_base)
file_base = common_base
elif base:
common_base = self._common_base(base, [str(files)])
if common_base:
bases.add(common_base)
file_base = common_base
c += str_files

if base:
if not files:
c.append(str(base))
root_dir = directory / base
else:
root_dir = directory
process = subprocess.run(
[
"python3",
Expand All @@ -377,7 +364,7 @@ def get_tests(
)
LOGGER.info(f"pytest collection finished with {process.returncode}")
tests = PytestStructure.parse_tests(process.stdout.decode("utf8"))
return self._normalize_paths(tests, bases, directory, root_dir)
return self._normalize_paths(tests, file_base, directory, root_dir)

@staticmethod
def __get_pytest_result__(
Expand Down

0 comments on commit 83277f7

Please sign in to comment.