From 729099f87d2681b1aa37cfe49cd37ba8cd0646ff Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 13 Sep 2022 12:02:02 +0200 Subject: [PATCH] test coverage for launch_instance(argv) --- jupyterhub/tests/test_app.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/jupyterhub/tests/test_app.py b/jupyterhub/tests/test_app.py index 593bc33f..9595c6a1 100644 --- a/jupyterhub/tests/test_app.py +++ b/jupyterhub/tests/test_app.py @@ -1,4 +1,5 @@ """Test the JupyterHub entry point""" +import asyncio import binascii import json import logging @@ -388,3 +389,33 @@ def test_hub_routespec( assert "may not receive" in caplog.text else: assert "may not receive" not in caplog.text + + +@pytest.mark.parametrize( + "argv, sys_argv", + [ + (None, ["jupyterhub", "--debug", "--port=1234"]), + (["--log-level=INFO"], ["jupyterhub"]), + ], +) +def test_launch_instance(request, argv, sys_argv): + class DummyHub(JupyterHub): + def launch_instance_async(self, argv): + # short-circuit initialize + # by indicating we are going to generate config in start + self.generate_config = True + return super().launch_instance_async(argv) + + async def start(self): + asyncio.get_running_loop().stop() + + DummyHub.clear_instance() + request.addfinalizer(DummyHub.clear_instance) + + with patch.object(sys, "argv", sys_argv): + DummyHub.launch_instance(argv) + hub = DummyHub.instance() + if argv is None: + assert hub.argv == sys_argv[1:] + else: + assert hub.argv == argv