diff options
-rw-r--r-- | alot/commands/globals.py | 6 | ||||
-rw-r--r-- | tests/commands/global_test.py | 11 |
2 files changed, 10 insertions, 7 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py index f99e5f31..224b671b 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -396,7 +396,7 @@ class CallCommand(Command): Command.__init__(self, **kwargs) self.command = command - def apply(self, ui): + async def apply(self, ui): try: hooks = settings.hooks if hooks: @@ -405,7 +405,9 @@ class CallCommand(Command): if k not in hooks.__dict__: hooks.__dict__[k] = v - exec(self.command) + t = eval(self.command) + if asyncio.iscoroutine(t): + await t except Exception as e: logging.exception(e) msg = 'an error occurred during execution of "%s":\n%s' diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py index 1122b3f7..48ddd34d 100644 --- a/tests/commands/global_test.py +++ b/tests/commands/global_test.py @@ -246,14 +246,15 @@ class TestExternalCommand(unittest.TestCase): class TestCallCommand(unittest.TestCase): - def test_synchronous_call(self): + @utilities.async_test + async def test_synchronous_call(self): ui = mock.Mock() cmd = g_commands.CallCommand('ui()') - cmd.apply(ui) + await cmd.apply(ui) ui.assert_called_once() - @unittest.expectedFailure - def test_async_call(self): + @utilities.async_test + async def test_async_call(self): async def func(obj): obj() @@ -264,5 +265,5 @@ class TestCallCommand(unittest.TestCase): with mock.patch('alot.commands.globals.settings.hooks', hooks): cmd = g_commands.CallCommand('hooks.func(ui)') - cmd.apply(ui) + await cmd.apply(ui) ui.assert_called_once() |