-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add pytest and implement a test runner
* use pytest as test runner * delete scripts folder and create a test folder * implement the test_runner at tests/test_runner.py
- Loading branch information
Showing
9 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ target/ | |
__pycache__ | ||
build/ | ||
*.egg-info/ | ||
artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import asyncio | ||
from asyncio.subprocess import Process | ||
import pytest | ||
import pytest_asyncio | ||
import logging | ||
import os | ||
|
||
from datetime import datetime | ||
from pathlib import Path | ||
from typing import Tuple | ||
|
||
from . import ranging, data_transfer | ||
|
||
PICA_BIN = Path("./target/debug/pica-server") | ||
DATA_FILE = Path("README.md") | ||
PICA_LOCALHOST = "127.0.0.1" | ||
|
||
logging.basicConfig(level=os.environ.get("PICA_LOGLEVEL", "DEBUG").upper()) # type: ignore | ||
|
||
|
||
def setup_artifacts(test_name: str) -> Tuple[Path, Path]: | ||
artifacts = Path("./artifacts") | ||
artifacts.mkdir(parents=True, exist_ok=True) | ||
|
||
current_dt = datetime.now() | ||
formatted_date = current_dt.strftime("%Y-%m-%d_%H-%M-%S-%f")[:-3] | ||
|
||
f1 = artifacts / f"{formatted_date}_pica_{test_name}_stdout.txt" | ||
f1.touch(exist_ok=True) | ||
|
||
f2 = artifacts / f"{formatted_date}_pica_{test_name}_stderr.txt" | ||
f2.touch(exist_ok=True) | ||
|
||
return (f1, f2) | ||
|
||
|
||
@pytest_asyncio.fixture | ||
async def pica_port(request, unused_tcp_port): | ||
(stdout, stderr) = setup_artifacts(request.node.name) | ||
if not PICA_BIN.exists(): | ||
raise FileNotFoundError(f"{PICA_BIN} not found") | ||
|
||
with stdout.open('w') as fstdout, stderr.open('w') as fstderr: | ||
process = await asyncio.create_subprocess_exec( | ||
PICA_BIN, | ||
"--uci-port", | ||
str(unused_tcp_port), | ||
stdout=fstdout, | ||
stderr=fstderr, | ||
) | ||
await asyncio.sleep(100 / 1000) # Let pica boot up | ||
|
||
yield unused_tcp_port | ||
|
||
process.terminate() | ||
await process.wait() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_ranging(pica_port): | ||
await ranging.run(PICA_LOCALHOST, pica_port) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_data_transfer(pica_port): | ||
await data_transfer.run(PICA_LOCALHOST, pica_port, DATA_FILE) |