Skip to content

Commit 9923ee3

Browse files
authored
tests: remove cleanup_func (#414)
The "vim" fixture uses a new session always. It was added when migrating to pytest in b65f62d, but is not really necessary. It could still be used to e.g. ensure tests are cleaning up after themselves, but this is also not necessary really. Adjusts existing tests, mainly with regard to handle IDs.
1 parent f3babfb commit 9923ee3

File tree

5 files changed

+6
-49
lines changed

5 files changed

+6
-49
lines changed

test/conftest.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
import textwrap
43

54
import pytest
65

@@ -9,50 +8,6 @@
98
pynvim.setup_logging("test")
109

1110

12-
@pytest.fixture(autouse=True)
13-
def cleanup_func(vim):
14-
fun = textwrap.dedent('''function! BeforeEachTest()
15-
set all&
16-
redir => groups
17-
silent augroup
18-
redir END
19-
for group in split(groups)
20-
exe 'augroup '.group
21-
autocmd!
22-
augroup END
23-
endfor
24-
autocmd!
25-
tabnew
26-
let curbufnum = eval(bufnr('%'))
27-
redir => buflist
28-
silent ls!
29-
redir END
30-
let bufnums = []
31-
for buf in split(buflist, '\\n')
32-
let bufnum = eval(split(buf, '[ u]')[0])
33-
if bufnum != curbufnum
34-
call add(bufnums, bufnum)
35-
endif
36-
endfor
37-
if len(bufnums) > 0
38-
exe 'silent bwipeout! '.join(bufnums, ' ')
39-
endif
40-
silent tabonly
41-
for k in keys(g:)
42-
exe 'unlet g:'.k
43-
endfor
44-
filetype plugin indent off
45-
mapclear
46-
mapclear!
47-
abclear
48-
comclear
49-
endfunction
50-
''')
51-
vim.command(fun)
52-
vim.command('call BeforeEachTest()')
53-
assert len(vim.tabpages) == len(vim.windows) == len(vim.buffers) == 1
54-
55-
5611
@pytest.fixture
5712
def vim():
5813
child_argv = os.environ.get('NVIM_CHILD_ARGV')

test/test_buffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def test_repr(vim):
10-
assert repr(vim.current.buffer) == "<Buffer(handle=2)>"
10+
assert repr(vim.current.buffer) == "<Buffer(handle=1)>"
1111

1212

1313
def test_get_length(vim):

test/test_tabpage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ def test_number(vim):
4545

4646

4747
def test_repr(vim):
48-
assert repr(vim.current.tabpage) == "<Tabpage(handle=2)>"
48+
assert repr(vim.current.tabpage) == "<Tabpage(handle=1)>"

test/test_vim.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def test_command_error(vim):
4545
def test_eval(vim):
4646
vim.command('let g:v1 = "a"')
4747
vim.command('let g:v2 = [1, 2, {"v3": 3}]')
48-
assert vim.eval('g:') == {'v1': 'a', 'v2': [1, 2, {'v3': 3}]}
48+
g = vim.eval('g:')
49+
assert g['v1'] == 'a'
50+
assert g['v2'] == [1, 2, {'v3': 3}]
4951

5052

5153
def test_call(vim):

test/test_window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ def test_handle(vim):
121121

122122

123123
def test_repr(vim):
124-
assert repr(vim.current.window) == "<Window(handle=1001)>"
124+
assert repr(vim.current.window) == "<Window(handle=1000)>"

0 commit comments

Comments
 (0)