-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test trace
command: execute a trace against testnet (#61)
* generate pytest file via test trace * test execution * capitalize constant & use removesuffix()
- Loading branch information
1 parent
75fe55d
commit 7186c0b
Showing
3 changed files
with
77 additions
and
8 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
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,57 @@ | ||
from os import PathLike | ||
from atomkraft.utils.project import project_root | ||
import os.path | ||
from datetime import datetime | ||
import pytest | ||
from ..reactor.reactor import get_reactor | ||
|
||
|
||
TRACE_TEST_STUB = """ | ||
from modelator.pytest.decorators import itf | ||
pytest_plugins = "{0}" | ||
@itf("{1}", keypath="{2}") | ||
def test_trace(): | ||
print("Successfully executed trace {1}") | ||
""" | ||
|
||
|
||
def test_trace(trace: PathLike, reactor: PathLike, keypath: str): | ||
""" | ||
Test blockchain by running one trace | ||
""" | ||
|
||
if reactor is None: | ||
reactor = get_reactor() | ||
|
||
root = project_root() | ||
if not root: | ||
raise RuntimeError( | ||
"could not find Atomkraft project: are you in the right directory?" | ||
) | ||
|
||
tests = os.path.join(root, "tests") | ||
if not os.path.isdir(tests): | ||
raise RuntimeError( | ||
"Atomkraft tests directory not found: have you executed `atomkraft init`?" | ||
) | ||
|
||
timestamp = datetime.now().isoformat(timespec="milliseconds") | ||
test_name = f"test_{str(trace)}_{timestamp}" | ||
test_name = ( | ||
test_name.replace("/", "_") | ||
.replace(".", "_") | ||
.replace(":", "_") | ||
.replace("-", "_") | ||
) | ||
test_path = os.path.join(tests, f"{test_name}.py") | ||
with open(test_path, "w") as test: | ||
print(f"Writing {test_name} ...") | ||
test.write( | ||
TRACE_TEST_STUB.format( | ||
str(reactor).replace("/", ".").removesuffix(".py"), trace, keypath | ||
) | ||
) | ||
print(f"Executing {test_name} ...") | ||
pytest.main(["-s", test_path]) |