Skip to content

Commit

Permalink
tests: remove cleanup_func (#414)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
blueyed committed Oct 18, 2019
1 parent f3babfb commit 9923ee3
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 49 deletions.
45 changes: 0 additions & 45 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
import textwrap

import pytest

Expand All @@ -9,50 +8,6 @@
pynvim.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')
Expand Down
2 changes: 1 addition & 1 deletion test/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def test_repr(vim):
assert repr(vim.current.buffer) == "<Buffer(handle=2)>"
assert repr(vim.current.buffer) == "<Buffer(handle=1)>"


def test_get_length(vim):
Expand Down
2 changes: 1 addition & 1 deletion test/test_tabpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def test_number(vim):


def test_repr(vim):
assert repr(vim.current.tabpage) == "<Tabpage(handle=2)>"
assert repr(vim.current.tabpage) == "<Tabpage(handle=1)>"
4 changes: 3 additions & 1 deletion test/test_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def test_command_error(vim):
def test_eval(vim):
vim.command('let g:v1 = "a"')
vim.command('let g:v2 = [1, 2, {"v3": 3}]')
assert vim.eval('g:') == {'v1': 'a', 'v2': [1, 2, {'v3': 3}]}
g = vim.eval('g:')
assert g['v1'] == 'a'
assert g['v2'] == [1, 2, {'v3': 3}]


def test_call(vim):
Expand Down
2 changes: 1 addition & 1 deletion test/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ def test_handle(vim):


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

0 comments on commit 9923ee3

Please sign in to comment.