Skip to content

Commit

Permalink
Timing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Jan 19, 2024
1 parent 9916439 commit 6c3f862
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/src/healthstatus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TestResult:
asset_path: str
outcome: Outcome
output: Optional[str] = None
elapsed: Optional[float] = None


@dataclass
Expand Down
23 changes: 22 additions & 1 deletion code/src/healthstatus/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import subprocess
import sys
import time
from typing import Optional
import anyio
from .config import MATNWB_INSTALL_DIR, PYNWB_OPEN_LOAD_NS_SCRIPT, TIMEOUT
Expand All @@ -16,23 +17,30 @@ async def run_test_command(
) -> TestResult:
if env is not None:
env = {**os.environ, **env}
elapsed: float | None = None
try:
with anyio.fail_after(TIMEOUT):
start = time.perf_counter()
r = await anyio.run_process(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=False,
env=env,
)
end = time.perf_counter()
elapsed = end - start
except TimeoutError:
return TestResult(
testname=testname, asset_path=asset.asset_path, outcome=Outcome.TIMEOUT
)
else:
if r.returncode == 0:
return TestResult(
testname=testname, asset_path=asset.asset_path, outcome=Outcome.PASS
testname=testname,
asset_path=asset.asset_path,
outcome=Outcome.PASS,
elapsed=elapsed,
)
else:
return TestResult(
Expand Down Expand Up @@ -65,6 +73,19 @@ async def matnwb_nwbRead(asset: Asset) -> TestResult:
)


async def dandi_ls(asset: Asset) -> TestResult:
return await run_test_command(
"dandi_ls",
asset,
["dandi", "ls", str(asset.filepath)],
env={"DANDI_CACHE": "ignore"},
)


TESTFUNCS = [pynwb_open_load_ns, matnwb_nwbRead]

TESTS = {t.__name__: t for t in TESTFUNCS}

TIMED_TEST_FUNCS = [*TESTFUNCS, dandi_ls]

TIMED_TESTS = {t.__name__: t for t in TIMED_TEST_FUNCS}

0 comments on commit 6c3f862

Please sign in to comment.