From 2f6526d108b3a8df527d2694c9ce3c46e438f963 Mon Sep 17 00:00:00 2001 From: ff137 Date: Wed, 6 Nov 2024 21:07:22 +0200 Subject: [PATCH] :art: Rename method and remove redundant main call Signed-off-by: ff137 --- acapy_agent/commands/provision.py | 11 +++-------- acapy_agent/commands/tests/test_provision.py | 13 ++++++++----- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/acapy_agent/commands/provision.py b/acapy_agent/commands/provision.py index 962b38dc8e..a463dd6e48 100644 --- a/acapy_agent/commands/provision.py +++ b/acapy_agent/commands/provision.py @@ -67,7 +67,7 @@ async def provision(settings: dict): raise ProvisionError("Error during provisioning") from e -def execute(argv: Sequence[str] = None): +def execute_provision(argv: Sequence[str] = None): """Entrypoint.""" parser = arg.create_argument_parser(prog=PROG) parser.prog += " provision" @@ -84,10 +84,5 @@ def execute(argv: Sequence[str] = None): loop.run_until_complete(provision(settings)) -def main(): - """Execute the main line.""" - if __name__ == "__main__": - execute() - - -main() +if __name__ == "__main__": + execute_provision() diff --git a/acapy_agent/commands/tests/test_provision.py b/acapy_agent/commands/tests/test_provision.py index 65d0d488bd..3fbeb00208 100644 --- a/acapy_agent/commands/tests/test_provision.py +++ b/acapy_agent/commands/tests/test_provision.py @@ -14,10 +14,10 @@ class TestProvision(IsolatedAsyncioTestCase): def test_bad_calls(self): with self.assertRaises(ArgsParseError): - test_module.execute([]) + test_module.execute_provision([]) with self.assertRaises(SystemExit): - test_module.execute(["bad"]) + test_module.execute_provision(["bad"]) async def test_provision_ledger_configured(self): profile = mock.MagicMock(close=mock.CoroutineMock()) @@ -43,11 +43,14 @@ async def test_provision_config_x(self): with self.assertRaises(test_module.ProvisionError): await test_module.provision({}) - def test_main(self): + def test_main_entry_point(self): + """Test that the execute_provision function is called when the module is run as main.""" with mock.patch.object(test_module, "__name__", "__main__"), mock.patch.object( - test_module, "execute", mock.MagicMock() + test_module, "execute_provision", mock.MagicMock() ) as mock_execute: - test_module.main() + import importlib + + importlib.reload(test_module) # Reload the module to trigger the main guard mock_execute.assert_called_once async def test_provision_should_store_provided_mediation_invite(self):