diff --git a/CHANGES.rst b/CHANGES.rst index a0b082c..e20698a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,9 @@ Changelog * Use blocking RPC call in ``Client.create_database``. Asynchronous method is removed in Odoo. +* Return the interactive namespace with ``main(interact=False)``. + It helps to integrate with third-party libraries, such as IPython. + * Remove a duplicate ``Logged in as ...`` line in interactive mode. * Remove the ``search+name_get`` undocumented feature which has diff --git a/erppeek.py b/erppeek.py index a1d10d5..8464bc0 100644 --- a/erppeek.py +++ b/erppeek.py @@ -1558,7 +1558,7 @@ def runcode(self, code): Console().interact('\033[A') -def main(): +def main(interact=_interact): description = ('Inspect data on Odoo objects. Use interactively ' 'or query a model (-m) and pass search terms or ' 'ids as positional parameters after the options.') @@ -1631,7 +1631,7 @@ def main(): if not client.user: client.connect() # Enter interactive mode - _interact(global_vars) + return interact(global_vars) if interact else global_vars if __name__ == '__main__': main() diff --git a/tests/test_interact.py b/tests/test_interact.py index 46b37b7..79425b4 100644 --- a/tests/test_interact.py +++ b/tests/test_interact.py @@ -31,6 +31,7 @@ def setUp(self): mock.patch('erppeek.Client._set_interactive', wraps=erppeek.Client._set_interactive).start() self.interact = mock.patch('erppeek._interact', wraps=erppeek._interact).start() self.infunc = mock.patch('code.InteractiveConsole.raw_input').start() + mock.patch('erppeek.main.__defaults__', (self.interact,)).start() def test_main(self): env_tuple = ('http://127.0.0.1:8069', 'database', 'usr', None)