From 4a9ef545deefd902a6984bedcba55b8c12fe4e40 Mon Sep 17 00:00:00 2001 From: goodki-d <185676088+goodki-d@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:52:35 +0530 Subject: [PATCH] chore: add test case --- tests/test_cli.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 67de4b7410..313a801b5d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -13,6 +13,7 @@ from sanic import __version__ from sanic.__main__ import main from sanic.cli.inspector_client import InspectorClient +from sanic.models.ctx_types import REPLLocal from .conftest import get_port @@ -404,3 +405,25 @@ def test_command_with_renamed_command(caplog): with patch("sys.argv", ["sanic", *args]): lines = capture(args, caplog) assert "BAZ" in lines + + +def test_add_local_method(app): + def foo(): ... + def bar(): + """bar method docstring.""" + + class Luffy: ... + + import os + + app.repl_ctx.add(foo) + app.repl_ctx.add(bar) + app.repl_ctx.add(Luffy) + app.repl_ctx.add(os, desc="Standard os module.") + + assert REPLLocal(foo, "foo", "") in app.repl_ctx._locals + assert ( + REPLLocal(bar, "bar", "bar method docstring.") in app.repl_ctx._locals + ) + assert REPLLocal(Luffy, "Luffy", "") in app.repl_ctx._locals + assert REPLLocal(os, "os", "Standard os module.") in app.repl_ctx._locals