1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
From: =?utf-8?q?V=C3=ADctor_Cuadrado_Juan?= <me@viccuad.me>
Date: Tue, 8 Jan 2019 14:50:27 +0100
Subject: Add test/conftest.py as not shipped in sdist
Forwarded: https://github.com/neovim/pynvim/issues/348
---
test/conftest.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 test/conftest.py
diff --git a/test/conftest.py b/test/conftest.py
new file mode 100644
index 0000000..8e6ebad
--- /dev/null
+++ b/test/conftest.py
@@ -0,0 +1,67 @@
+import json
+import os
+import textwrap
+
+import neovim
+import pytest
+
+neovim.setup_logging("test")
+
+
+@pytest.fixture(autouse=True)
+def cleanup_func(vim):
+ fun = textwrap.dedent('''function! BeforeEachTest()
+ set all&
+ redir => groups
+ silent augroup
+ redir END
+ for group in split(groups)
+ exe 'augroup '.group
+ autocmd!
+ augroup END
+ endfor
+ autocmd!
+ tabnew
+ let curbufnum = eval(bufnr('%'))
+ redir => buflist
+ silent ls!
+ redir END
+ let bufnums = []
+ for buf in split(buflist, '\\n')
+ let bufnum = eval(split(buf, '[ u]')[0])
+ if bufnum != curbufnum
+ call add(bufnums, bufnum)
+ endif
+ endfor
+ if len(bufnums) > 0
+ exe 'silent bwipeout! '.join(bufnums, ' ')
+ endif
+ silent tabonly
+ for k in keys(g:)
+ exe 'unlet g:'.k
+ endfor
+ filetype plugin indent off
+ mapclear
+ mapclear!
+ abclear
+ comclear
+ endfunction
+ ''')
+ vim.command(fun)
+ vim.command('call BeforeEachTest()')
+ assert len(vim.tabpages) == len(vim.windows) == len(vim.buffers) == 1
+
+
+@pytest.fixture
+def vim():
+ child_argv = os.environ.get('NVIM_CHILD_ARGV')
+ listen_address = os.environ.get('NVIM_LISTEN_ADDRESS')
+ if child_argv is None and listen_address is None:
+ child_argv = '["nvim", "-u", "NONE", "--embed"]'
+
+ if child_argv is not None:
+ editor = neovim.attach('child', argv=json.loads(child_argv))
+ else:
+ editor = neovim.attach('socket', path=listen_address)
+
+ return editor
|