Skip to content

Commit

Permalink
more (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan authored Jan 16, 2024
1 parent 6467c50 commit 0561560
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions phlop/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import contextlib
import os
import platform
from pathlib import Path


Expand Down Expand Up @@ -45,3 +46,7 @@ def write_to_file(file, contents, mode="w", skip_if_empty=True):
f.write(contents)
except IOError as e:
raise RuntimeError(f"Failed to write to file {file}: {e}")


def env_sep():
return ";" if any(platform.win32_ver()) else ":"
2 changes: 2 additions & 0 deletions phlop/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@


def classes_in_file(file, subclasses_only=None, fail_on_import_error=True):
assert file
module = str(file).replace(os.path.sep, ".")[:-3]
assert module

if subclasses_only is not None and not isinstance(subclasses_only, list):
subclasses_only = [subclasses_only]
Expand Down
12 changes: 12 additions & 0 deletions phlop/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#


import os
import sys
from contextlib import contextmanager

Expand All @@ -19,3 +20,14 @@ def extend_sys_path(paths):
yield
finally:
sys.path = old_path


@contextmanager
def extend_env(**environ):
old_env = dict(os.environ)
os.environ.update(environ)
try:
yield
finally:
os.environ.clear()
os.environ.update(old_env)
14 changes: 8 additions & 6 deletions phlop/testing/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from pathlib import Path

from phlop.app.cmake import list_tests as get_cmake_tests
from phlop.os import pushd
from phlop.os import env_sep
from phlop.proc import run
from phlop.reflection import classes_in_file
from phlop.sys import extend_sys_path

_LOG_DIR = Path(os.environ.get("PHLOP_LOG_DIR", os.getcwd()))

Expand All @@ -25,6 +26,9 @@ class TestCase:
working_dir: str = field(default_factory=lambda: None)
log_file_path: str = field(default_factory=lambda: None)

def __post_init__(self):
self.cmd = self.cmd.strip()


class TestBatch:
def __init__(self, tests, cores=1):
Expand Down Expand Up @@ -101,13 +105,11 @@ def load_test_cases_in(


def load_test_cases_from_cmake(ctest_test):
ppath = f"{ctest_test.working_dir}:{ctest_test.env.get('PYTHONPATH','')}"
ctest_test.env["PYTHONPATH"] = ppath
with pushd(ctest_test.working_dir):
print("ctest_test", ctest_test.cmd)
ppath = ctest_test.env.get("PYTHONPATH", "")
with extend_sys_path([ctest_test.working_dir] + ppath.split(env_sep())):
pyfile = ctest_test.cmd.split(" ")[-1]
return load_test_cases_in(
classes_in_file(pyfile, unittest.TestCase, fail_on_import_error=False),
classes_in_file(pyfile, unittest.TestCase, fail_on_import_error=True),
env=ctest_test.env,
working_dir=ctest_test.working_dir,
log_file_path=_LOG_DIR
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[project]
name = "phlop"
version = "0.0.7"
version = "0.0.8"

dependencies = [

]

description = "stuff and things"
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="phlop",
version="0.0.7",
version="0.0.8",
cmdclass={},
classifiers=[],
include_package_data=True,
Expand Down

0 comments on commit 0561560

Please sign in to comment.