Files
Dario Gabriel LipicarandClaude Opus 4.7 c87a41a56d feat: Python wrapper for the logoscore CLI
Thin Python API that spawns `logoscore` subprocesses internally so test
authors can drive a Logos runtime from Python without shelling out and
parsing output by hand (see logos-liblogos#120).

Features:
- LogoscoreDaemon context manager: spawns `logoscore -D` with an isolated
  --config-dir, waits for daemon.json, auto-stops on __exit__
- LogoscoreClient: status, list_modules, module_info, load/unload/reload,
  call, stats, stop — maps CLI exit codes to typed exceptions
- Callback-based events via `client.on_event(...)`, backed by a
  `logoscore watch` watcher thread that parses NDJSON
- No runtime deps (stdlib only), Python >= 3.10
- Nix flake: devShell + unit + integration checks using logos-test-modules

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 12:58:18 -03:00

31 lines
964 B
Python

from logoscore.errors import (
DaemonNotRunningError,
LogoscoreError,
MethodError,
ModuleError,
from_exit_code,
)
def test_exit_code_mapping():
assert isinstance(from_exit_code(2, "x"), DaemonNotRunningError)
assert isinstance(from_exit_code(3, "x"), ModuleError)
assert isinstance(from_exit_code(4, "x"), MethodError)
# Unknown codes fall back to the base class
assert isinstance(from_exit_code(1, "x"), LogoscoreError)
assert isinstance(from_exit_code(99, "x"), LogoscoreError)
def test_error_attributes():
exc = from_exit_code(3, "boom", stderr="std", error_code="MODULE_NOT_FOUND")
assert exc.exit_code == 3
assert exc.stderr == "std"
assert exc.code == "MODULE_NOT_FOUND"
assert "boom" in str(exc)
def test_error_hierarchy():
assert issubclass(DaemonNotRunningError, LogoscoreError)
assert issubclass(ModuleError, LogoscoreError)
assert issubclass(MethodError, LogoscoreError)