Skip to content

Commit

Permalink
🎨 Rename method and remove redundant main call
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <ff137@proton.me>
  • Loading branch information
ff137 committed Nov 6, 2024
1 parent 1232626 commit 2f6526d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
11 changes: 3 additions & 8 deletions acapy_agent/commands/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
13 changes: 8 additions & 5 deletions acapy_agent/commands/tests/test_provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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):
Expand Down

0 comments on commit 2f6526d

Please sign in to comment.