Add test
This commit is contained in:
parent
5d96d6d3d9
commit
05a7f982f2
|
@ -1 +1 @@
|
||||||
__version__ = "0.1.15"
|
__version__ = "0.1.16"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "falyx"
|
name = "falyx"
|
||||||
version = "0.1.15"
|
version = "0.1.16"
|
||||||
description = "Reliable and introspectable async CLI action framework."
|
description = "Reliable and introspectable async CLI action framework."
|
||||||
authors = ["Roland Thomas Jr <roland@rtj.dev>"]
|
authors = ["Roland Thomas Jr <roland@rtj.dev>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from falyx import Action, Falyx
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_run_key():
|
||||||
|
"""Test if Falyx can run in run key mode."""
|
||||||
|
falyx = Falyx("Run Key Test")
|
||||||
|
|
||||||
|
# Add a simple command
|
||||||
|
falyx.add_command(
|
||||||
|
key="T",
|
||||||
|
description="Test Command",
|
||||||
|
action=lambda: "Hello, World!",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run the CLI
|
||||||
|
result = await falyx.run_key("T")
|
||||||
|
assert result == "Hello, World!"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_run_key_recover():
|
||||||
|
"""Test if Falyx can recover from a failure in run key mode."""
|
||||||
|
falyx = Falyx("Run Key Recovery Test")
|
||||||
|
|
||||||
|
state = {"count": 0}
|
||||||
|
|
||||||
|
async def flaky():
|
||||||
|
if not state["count"]:
|
||||||
|
state["count"] += 1
|
||||||
|
raise RuntimeError("Random failure!")
|
||||||
|
return "ok"
|
||||||
|
|
||||||
|
# Add a command that raises an exception
|
||||||
|
falyx.add_command(
|
||||||
|
key="E",
|
||||||
|
description="Error Command",
|
||||||
|
action=Action("flaky", flaky),
|
||||||
|
retry=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
result = await falyx.run_key("E")
|
||||||
|
assert result == "ok"
|
Loading…
Reference in New Issue