Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store test data with report #84

Merged
merged 5 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion atomkraft/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def RequiredFileOption(help, default):
def trace(
# currently, require the trace to be present.
# later, there will be an option to pick up the last one from the model
verbose: bool = typer.Option(
False, "--verbose", "-v", help="Output logging on console"
),
hvanz marked this conversation as resolved.
Show resolved Hide resolved
trace: typer.FileText = RequiredFileOption("trace to execute", "model"),
reactor: typer.FileText = FileOption("reactor to interpret the trace", "reactor"),
keypath: str = typer.Option(
Expand All @@ -39,7 +42,9 @@ def trace(
Test blockchain by running one trace
"""

test_trace(trace.name, reactor if reactor is None else reactor.name, keypath)
test_trace(
trace.name, reactor if reactor is None else reactor.name, keypath, verbose
hvanz marked this conversation as resolved.
Show resolved Hide resolved
)


@app.command()
Expand Down
37 changes: 35 additions & 2 deletions atomkraft/test/trace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os.path
import shutil
from datetime import datetime
from os import PathLike
from pathlib import Path
from typing import List

import pytest
from atomkraft.utils.project import project_root
Expand All @@ -18,7 +21,15 @@ def test_trace():
"""


def test_trace(trace: PathLike, reactor: PathLike, keypath: str):
def copy(src_paths: List[Path], dst_path: Path):
for src in src_paths:
if src.is_dir():
shutil.copytree(src, dst_path / src.name)
else:
shutil.copy2(src, dst_path)


def test_trace(trace: PathLike, reactor: PathLike, keypath: str, verbose: bool):
"""
Test blockchain by running one trace
"""
Expand Down Expand Up @@ -55,4 +66,26 @@ def test_trace(trace: PathLike, reactor: PathLike, keypath: str):
)
)
print(f"Executing {test_name} ...")
pytest.main(["-s", test_path])

report_dir = root / "reports" / test_name
report_dir.mkdir(parents=True)
hvanz marked this conversation as resolved.
Show resolved Hide resolved

logging_file = report_dir / "log.txt"
hvanz marked this conversation as resolved.
Show resolved Hide resolved

pytest_report_file = report_dir / "report.jsonl"
hvanz marked this conversation as resolved.
Show resolved Hide resolved

pytest_args = [
"--log-file-level=INFO",
f"--log-file={logging_file}",
f"--report-log={pytest_report_file}",
]

if verbose:
pytest_args.append("-rP")
hvanz marked this conversation as resolved.
Show resolved Hide resolved
pytest_args.append("--log-cli-level=INFO")

pytest.main(pytest_args + [test_path])

copy([Path(trace), root / ".atomkraft" / "nodes"], report_dir)

print(f"Test data is saved at {report_dir}")
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ websockets = "^10.3"
GitPython = "^3.1.27"
tomlkit = "^0.11.1"
case-converter = "^1.1.0"
pytest-reportlog = "^0.1.2"

[build-system]
requires = ["poetry-core>=1.0.0", "setuptools>=42"]
Expand Down