Update tests

This commit is contained in:
Daniel Siepmann 2020-04-27 11:06:55 +02:00
parent ad92d10f12
commit 9b9965094e
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
2 changed files with 30 additions and 7 deletions

View file

@ -48,4 +48,4 @@ Install dependencies:
Run tests:
``cd rplugin && python -m unittest test.test_neotags``
``docker run -it --rm -v $PWD/rplugin:/project -w /project registry.gitlab.com/danielsiepmann/neotags:latest python -m unittest test.test_neotags``

View file

@ -1,3 +1,4 @@
import unittest
from unittest.mock import Mock
from unittest.mock import MagicMock
from pyfakefs import fake_filesystem_unittest
@ -6,7 +7,6 @@ import os
from python3.neotags import NeotagsPlugin
class TestNeotagsPlugin(fake_filesystem_unittest.TestCase):
def setUp(self):
@ -18,22 +18,42 @@ class TestNeotagsPlugin(fake_filesystem_unittest.TestCase):
self.plugin = NeotagsPlugin(Mock(pynvim.api.nvim))
def test_default_options(self):
self.assertEqual('ctags', self.plugin.options['ctags_cmd'])
self.assertEqual('tags', self.plugin.options['tags_filename'])
self.assertEqual('ctags', self.plugin.options['ctags_cmd'])
self.assertEqual(False, self.plugin.options['logging'])
def test_custom_options(self):
self.plugin.nvim.configure_mock(vars={})
self.plugin.nvim.vars['neotags_tags_filename'] = 'new_tags'
self.plugin.nvim.vars['neotags_ctags_cmd'] = 'new_ctags'
self.plugin.nvim.vars['neotags_logging'] = True
def eval(argument):
if argument == 'g:neotags_tags_filename':
return 'new_tags'
if argument == 'g:neotags_ctags_cmd':
return 'new_ctags'
if argument == 'g:neotags_logging':
return True
self.plugin.nvim.configure_mock(eval=eval)
self.plugin.update_settings()
self.assertEqual('new_tags', self.plugin.options['tags_filename'])
self.assertEqual('new_ctags', self.plugin.options['ctags_cmd'])
self.assertEqual(True, self.plugin.options['logging'])
def test_fallback_option(self):
def eval(argument):
if argument == 'g:neotags_tags_filename':
return 'new_tags'
if argument == 'g:neotags_ctags_cmd':
raise pynvim.api.nvim.NvimError('')
if argument == 'g:neotags_logging':
return True
self.plugin.nvim.configure_mock(eval=eval)
self.plugin.update_settings()
self.assertEqual('new_tags', self.plugin.options['tags_filename'])
self.assertEqual('ctags', self.plugin.options['ctags_cmd'])
self.assertEqual(True, self.plugin.options['logging'])
def test_debug_logs_to_nvim_when_logging_is_active(self):
self.plugin.options['logging'] = True
self.plugin.nvim.out_write = MagicMock()
@ -128,3 +148,6 @@ class TestNeotagsPlugin(fake_filesystem_unittest.TestCase):
self.plugin.strip_existing_tags(tags_file, os.path.basename(filename))
with open(tags_file) as f, open(expected_tags_file) as e:
self.assertEqual(e.read(), f.read())
if __name__ == '__main__':
unittest.main()