Skip to content

Commit

Permalink
#88: Fix unrelated failing test of powershell autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
borissmidt committed Jul 6, 2023
1 parent 32e5f3a commit 85159fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
12 changes: 2 additions & 10 deletions tests/test_completion/test_completion_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
from unittest import mock

import shellingham
import typer
from typer.testing import CliRunner

from docs_src.commands.index import tutorial001 as mod
from typer.testing import CliRunner

runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)
app = mod.app


def test_completion_install_no_shell():
Expand Down Expand Up @@ -144,12 +142,6 @@ def test_completion_install_fish():
assert "completion installed in" in result.stdout
assert "Completion will take effect once you restart the terminal" in result.stdout


runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)


def test_completion_install_powershell():
completion_path: Path = (
Path.home() / f".config/powershell/Microsoft.PowerShell_profile.ps1"
Expand Down
12 changes: 5 additions & 7 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@
except ImportError: # pragma: nocover
rich = None # type: ignore

try:
from asyncio import Loop
except ImportError: # pragma: nocover
Loop = Any # type: ignore
from asyncio import AbstractEventLoop

_original_except_hook = sys.excepthook
_typer_developer_exception_attr_name = "__typer_developer_exception__"
Expand Down Expand Up @@ -145,7 +142,7 @@ def __init__(
pretty_exceptions_enable: bool = True,
pretty_exceptions_show_locals: bool = True,
pretty_exceptions_short: bool = True,
loop_factory: Optional[Callable[[], Loop]] = None,
loop_factory: Optional[Callable[[], AbstractEventLoop]] = None,
):
self._add_completion = add_completion
self.rich_markup_mode: MarkupMode = rich_markup_mode
Expand Down Expand Up @@ -245,7 +242,7 @@ def command(
def decorator(f: CommandFunctionType) -> CommandFunctionType:
def add_runner(f: CommandFunctionType) -> CommandFunctionType:
@wraps(f)
def runner(*args, **kwargs) -> Any:
def run_wrapper(*args, **kwargs) -> Any:
if sys.version_info >= (3, 11) and self.loop_factory:
with asyncio.Runner(loop_factory=self.loop_factory) as runner:
return runner.run(f(*args, **kwargs))
Expand All @@ -254,7 +251,7 @@ def runner(*args, **kwargs) -> Any:
else:
asyncio.get_event_loop().run_until_complete(asyncio.wait(f(*args, **kwargs)))

return runner
return run_wrapper

if inspect.iscoroutinefunction(f):
callback = add_runner(f)
Expand All @@ -279,6 +276,7 @@ def runner(*args, **kwargs) -> Any:
rich_help_panel=rich_help_panel,
)
)
return f


return decorator
Expand Down

0 comments on commit 85159fb

Please sign in to comment.