Skip to content

Commit

Permalink
updated the tox file and the README for test instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Meitham Jamaa committed Apr 24, 2018
1 parent c609e89 commit dcf80da
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,21 @@ to use it for the plugin host.
To run the tests execute

```sh
nosetests
pytest
```

This will run the tests in an embedded instance of nvim.
If you want to test a different version than `nvim` in `$PATH` use
```sh
NVIM_CHILD_ARGV='["/path/to/nvim", "-u", "NONE", "--embed"]' nosetests
NVIM_CHILD_ARGV='["/path/to/nvim", "-u", "NONE", "--embed"]' pytest
```

Alternatively, if you want to see the state of nvim, you could use

```sh
export NVIM_LISTEN_ADDRESS=/tmp/nvimtest
xterm -e "nvim -u NONE"&
nosetests
pytest
```

But note you need to restart nvim every time you run the tests! Substitute your
Expand Down
16 changes: 8 additions & 8 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
neovim.setup_logging("test")


@pytest.fixture
def cleanup_func():
return textwrap.dedent(''':function BeforeEachTest()
@pytest.fixture(autouse=True)
def cleanup_func(vim):
fun = textwrap.dedent(''':function BeforeEachTest()
set all&
redir => groups
silent augroup
Expand Down Expand Up @@ -47,10 +47,13 @@ def cleanup_func():
comclear
endfunction
''')
vim.input(fun)
vim.command('call BeforeEachTest()')
assert len(vim.tabpages) == len(vim.windows) == len(vim.buffers) == 1


@pytest.fixture()
def vim(cleanup_func):
@pytest.fixture
def vim():
child_argv = os.environ.get('NVIM_CHILD_ARGV')
listen_address = os.environ.get('NVIM_LISTEN_ADDRESS')
if child_argv is None and listen_address is None:
Expand All @@ -61,7 +64,4 @@ def vim(cleanup_func):
else:
editor = neovim.attach('socket', path=listen_address)

# editor.input(cleanup_func)
# editor.command('call BeforeEachTest()')
assert len(editor.tabpages) == len(editor.windows) == len(editor.buffers) == 1
return editor
14 changes: 6 additions & 8 deletions test/test_decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from nose.tools import with_setup, eq_ as eq, ok_ as ok

from neovim.plugin.decorators import command


Expand All @@ -10,21 +8,21 @@ def function():

# ensure absence with default value of None
decorated = command('test')(function)
ok('count' not in decorated._nvim_rpc_spec['opts'])
assert 'count' not in decorated._nvim_rpc_spec['opts']

# ensure absence with explicit value of None
count_value = None
decorated = command('test', count=count_value)(function)
ok('count' not in decorated._nvim_rpc_spec['opts'])
assert 'count' not in decorated._nvim_rpc_spec['opts']

# Test presesence with value of 0
count_value = 0
decorated = command('test', count=count_value)(function)
ok('count' in decorated._nvim_rpc_spec['opts'])
eq(decorated._nvim_rpc_spec['opts']['count'], count_value)
assert 'count' in decorated._nvim_rpc_spec['opts']
assert decorated._nvim_rpc_spec['opts']['count'] == count_value

# Test presence with value of 1
count_value = 1
decorated = command('test', count=count_value)(function)
ok('count' in decorated._nvim_rpc_spec['opts'])
eq(decorated._nvim_rpc_spec['opts']['count'], count_value)
assert 'count' in decorated._nvim_rpc_spec['opts']
assert decorated._nvim_rpc_spec['opts']['count'] == count_value
19 changes: 4 additions & 15 deletions test/test_vim.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# -*- coding: utf-8 -*-
<<<<<<< HEAD
import os, sys, tempfile
from nose.tools import with_setup, eq_ as eq, ok_ as ok
from test_common import vim, cleanup
=======
import os
import sys
import tempfile
>>>>>>> switched to pytest


def source(vim, code):
Expand All @@ -31,14 +26,9 @@ def test_command(vim):
os.unlink(fname)


<<<<<<< HEAD
def test_command_output():
eq(vim.command_output('echon "test"'), 'test')
=======
def test_command_output(vim):
assert vim.command_output('echo "test"') == '\ntest'

>>>>>>> switched to pytest

def test_eval(vim):
vim.command('let g:v1 = "a"')
Expand Down Expand Up @@ -165,8 +155,7 @@ def test_hash(vim):
assert d[vim.current.buffer] == 'beta'


@with_setup(setup=cleanup)
def test_cwd():
def test_cwd(vim):
pycmd = 'python'
if sys.version_info >= (3, 0):
pycmd = 'python3'
Expand All @@ -177,5 +166,5 @@ def test_cwd():
vim.command('cd test')
cwd_vim = vim.command_output('pwd')
cwd_python = vim.command_output('{} print(os.getcwd())'.format(pycmd))
eq(cwd_vim, cwd_python)
ok(cwd_python != cwd_before)
assert cwd_python == cwd_vim
assert cwd_python != cwd_before
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ envlist =

[testenv]
deps=
nose
pytest
pytest-xdist
pyuv: pyuv
commands=nosetests
commands=python -m pytest -s

[testenv:checkqa]
deps =
Expand Down

0 comments on commit dcf80da

Please sign in to comment.