Add tests for __main__.py

This commit is contained in:
Roland Thomas Jr 2025-05-05 18:32:57 -04:00
parent 6f159810b2
commit 2fee87ade9
Signed by: roland
GPG Key ID: 7C3C2B085A4C2872
4 changed files with 17 additions and 13 deletions

View File

@ -50,7 +50,7 @@ def get_falyx_parsers() -> FalyxParsers:
return falyx_parsers return falyx_parsers
def main(args: Namespace) -> Any: def run(args: Namespace) -> Any:
if args.command == "init": if args.command == "init":
from falyx.init import init_project from falyx.init import init_project
@ -77,7 +77,11 @@ def main(args: Namespace) -> Any:
return asyncio.run(flx.run()) return asyncio.run(flx.run())
if __name__ == "__main__": def main():
parsers = get_falyx_parsers() parsers = get_falyx_parsers()
args = parsers.parse_args() args = parsers.parse_args()
main(args) run(args)
if __name__ == "__main__":
main()

View File

@ -1 +1 @@
__version__ = "0.1.13" __version__ = "0.1.14"

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "falyx" name = "falyx"
version = "0.1.13" version = "0.1.14"
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"

View File

@ -5,7 +5,7 @@ from pathlib import Path
import pytest import pytest
from falyx.__main__ import bootstrap, find_falyx_config, get_falyx_parsers, main from falyx.__main__ import bootstrap, find_falyx_config, get_falyx_parsers, run
def test_find_falyx_config(): def test_find_falyx_config():
@ -64,11 +64,11 @@ def test_parse_args():
assert args.command == "init-global" assert args.command == "init-global"
def test_main(): def test_run():
"""Test if the main function works correctly.""" """Test if the run function works correctly."""
falyx_parsers = get_falyx_parsers() falyx_parsers = get_falyx_parsers()
args = falyx_parsers.parse_args(["init", "test_project"]) args = falyx_parsers.parse_args(["init", "test_project"])
main(args) run(args)
assert args.command == "init" assert args.command == "init"
assert args.name == "test_project" assert args.name == "test_project"
# Check if the project directory was created # Check if the project directory was created
@ -79,7 +79,7 @@ def test_main():
Path("test_project").rmdir() Path("test_project").rmdir()
# Test init-global # Test init-global
args = falyx_parsers.parse_args(["init-global"]) args = falyx_parsers.parse_args(["init-global"])
main(args) run(args)
# Check if the global config directory was created # Check if the global config directory was created
assert (Path.home() / ".config" / "falyx" / "falyx.yaml").exists() assert (Path.home() / ".config" / "falyx" / "falyx.yaml").exists()
# Clean up # Clean up
@ -92,7 +92,7 @@ def test_no_bootstrap():
"""Test if the main function works correctly when no config file is found.""" """Test if the main function works correctly when no config file is found."""
falyx_parsers = get_falyx_parsers() falyx_parsers = get_falyx_parsers()
args = falyx_parsers.parse_args(["list"]) args = falyx_parsers.parse_args(["list"])
assert main(args) is None assert run(args) is None
# Check if the task was run # Check if the task was run
assert args.command == "list" assert args.command == "list"
@ -101,12 +101,12 @@ def test_run_test_project():
"""Test if the main function works correctly with a test project.""" """Test if the main function works correctly with a test project."""
falyx_parsers = get_falyx_parsers() falyx_parsers = get_falyx_parsers()
args = falyx_parsers.parse_args(["init", "test_project"]) args = falyx_parsers.parse_args(["init", "test_project"])
main(args) run(args)
args = falyx_parsers.parse_args(["run", "B"]) args = falyx_parsers.parse_args(["run", "B"])
os.chdir("test_project") os.chdir("test_project")
with pytest.raises(SystemExit): with pytest.raises(SystemExit):
assert main(args) == "Build complete!" assert run(args) == "Build complete!"
os.chdir("..") os.chdir("..")
shutil.rmtree("test_project") shutil.rmtree("test_project")
assert not Path("test_project").exists() assert not Path("test_project").exists()