From 63abc7c99d13a9099bb949d4727044e7bddc4034 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 15 Oct 2019 15:59:13 +0200 Subject: [PATCH 1/2] tests: remove cleanup_func 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 | 44 -------------------------------------------- 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(+), 48 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index ade85aba..b503b624 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -9,50 +9,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) == "" From 4d495fbc9d127e1e2acaccd5ce816b25120b43a9 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 15 Oct 2019 16:34:10 +0200 Subject: [PATCH 2/2] lint --- test/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/conftest.py b/test/conftest.py index b503b624..ddd4d687 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,6 +1,5 @@ import json import os -import textwrap import pytest