ExecApp's --target parameter and the ec.Local.__init__()'s uri argument carry "local" as their default value which was meant as a keyword but doesn't pass as an URI. Fix that. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0 Signed-off-by: Jan Lindemann <jan@janware.com>
69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import sys
|
|
|
|
from typing import TYPE_CHECKING, override
|
|
|
|
from jw.pkg.lib.Cmd import Cmd
|
|
from jw.pkg.lib.ExecApp import ExecApp
|
|
|
|
if TYPE_CHECKING:
|
|
from argparse import Namespace
|
|
|
|
from jw.pkg.lib.App import App
|
|
|
|
# -- A minimal root command so the app can be built without a command tree.
|
|
|
|
class RootCmd(Cmd):
|
|
|
|
def __init__(self, parent: App | Cmd) -> None:
|
|
super().__init__(parent, 'root', 'Root command')
|
|
|
|
@override
|
|
async def _run(self, args: Namespace) -> None:
|
|
pass
|
|
|
|
# -- Counts the close() calls made by App.__aexit__() when the async context
|
|
# manager exits.
|
|
|
|
class RecordingExecApp(ExecApp):
|
|
|
|
closed = 0
|
|
|
|
@override
|
|
def close(self) -> None:
|
|
RecordingExecApp.closed += 1
|
|
super().close()
|
|
|
|
# -- App.__init__ builds the parser from sys.argv, so point it at a clean
|
|
# command line while constructing the app.
|
|
|
|
saved_argv = sys.argv
|
|
sys.argv = ['jw-pkg-test']
|
|
try:
|
|
app = RecordingExecApp(description = 'ExecApp test', root = RootCmd)
|
|
finally:
|
|
sys.argv = saved_argv
|
|
|
|
# -- ExecApp registers the exec-related options on the top-level parser.
|
|
|
|
opts = [o for a in app.parser._actions for o in getattr(a, 'option_strings', ())]
|
|
for opt in ('--interactive', '--verbose', '--target'):
|
|
assert opt in opts, f'{opt} must be registered by ExecApp'
|
|
|
|
# -- The default target is a conforming URI: a bare keyword would
|
|
# be parsed as a file path, and a downstream URI round-trip
|
|
# would misread it as a hostname
|
|
assert app.parser.get_default('target') == 'local://'
|
|
|
|
# -- Exiting the async context must close the app, through the
|
|
# App.__aexit__() that ExecApp.__aexit__() chains to.
|
|
async def exit_context() -> None:
|
|
async with app:
|
|
pass
|
|
|
|
asyncio.run(exit_context())
|
|
assert RecordingExecApp.closed == 1, 'exiting the app context must close the app'
|
|
|
|
print('All ExecApp tests passed')
|