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