From 9923ee3d4db283035e3ee660f1944d8c1632286f Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 18 Oct 2019 15:33:36 +0200 Subject: [PATCH] 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. --- test/conftest.py | 45 -------------------------------------------- test/test_buffer.py | 2 +- test/test_tabpage.py | 2 +- test/test_vim.py | 4 +++- test/test_window.py | 2 +- 5 files changed, 6 insertions(+), 49 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index ade85aba..ddd4d687 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,6 +1,5 @@ import json import os -import textwrap import pytest @@ -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') diff --git a/test/test_buffer.py b/test/test_buffer.py index 0f566660..baf38f59 100644 --- a/test/test_buffer.py +++ b/test/test_buffer.py @@ -7,7 +7,7 @@ def test_repr(vim): - assert repr(vim.current.buffer) == "" + assert repr(vim.current.buffer) == "" def test_get_length(vim): diff --git a/test/test_tabpage.py b/test/test_tabpage.py index 858152da..51c64a5b 100644 --- a/test/test_tabpage.py +++ b/test/test_tabpage.py @@ -45,4 +45,4 @@ def test_number(vim): def test_repr(vim): - assert repr(vim.current.tabpage) == "" + assert repr(vim.current.tabpage) == "" diff --git a/test/test_vim.py b/test/test_vim.py index df5de106..b9ae6a46 100644 --- a/test/test_vim.py +++ b/test/test_vim.py @@ -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): diff --git a/test/test_window.py b/test/test_window.py index 210ba798..bc48aeab 100644 --- a/test/test_window.py +++ b/test/test_window.py @@ -121,4 +121,4 @@ def test_handle(vim): def test_repr(vim): - assert repr(vim.current.window) == "" + assert repr(vim.current.window) == ""