[execnet-dev] testing vim with execnet

holger krekel holger at merlinux.eu
Fri Nov 20 19:48:16 CET 2009


Hi Adam,

i am curious: how does the setup of the vim_gateway funcarg look like? 
And how should i best install vim-bindings on an ubuntu 9.04 machine
in order to run such code as you post? 

best,
holger

On Thu, Nov 19, 2009 at 18:29 +0100, Adam wrote:
> [1] I'm either making a stupid mistake or something really funky is
>     going on. If I type this into vim directly (without the vim.command
>     everything works.
> 
>     Left for the interested. Irrelevant now as [2] works well:
> 
>     >>> def test_execnet_buffer_pickle(vim_gateway):
>     >>>     import pickle
>     >>>     channel = vim_gateway.remote_exec(r"""
>     ...         import vim
>     ...         vim.command('py import pickle')
>     ...         vim.command('py import vim')
>     ...         vim.command('py b = pickle.dumps([1, 2, 3])')
>     ...         vim.command('py if b == "": b = "empty"')
>     ...         vim.command('py vim.current.buffer[0] = b.split("\n")[0]')
>     ...         vim.command('py if vim.current.buffer[0] == "": vim.current.buffer[0] = "broken"')
>     >>>         channel.send(vim.current.buffer[0])""")
>     >>>     buf = channel.receive()
>     >>>     channel.close()
>     >>>     assert buf != 'broken'    # fails
>     >>>     #assert '\n'.join(buf) == pickle.dumps([1, 2, 3])    # '(lp0\nI1\naI2\naI3\na.'
> 
> 
> [2] The solution:
> 
>     >>> def test_execnet_eval_pickle(vim_gateway):
>     >>>     import pickle
>     >>>     channel = vim_gateway.remote_exec(r"""
>     ...         import vim
>     ...         vim.command('py import pickle')
>     ...         vim.command('py import vim')
>     ...         vim.command('py b = pickle.dumps([1, 2, 3])')
>     ...         vim.command('''py vim.command("let execnet='%s'" % b)''')
>     ...         b = vim.eval("execnet")
>     ...         channel.send(b)""")
>     >>>     buf = channel.receive()
>     >>>     channel.close()
>     >>>     assert buf == pickle.dumps([1, 2, 3])    # passes




More information about the execnet-dev mailing list