TASK: Add further tests
This commit is contained in:
parent
3c3289df3c
commit
73ad18d317
3 changed files with 80 additions and 2 deletions
7
rplugin/test/templates/example.py
Normal file
7
rplugin/test/templates/example.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
class SomeClass(object):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def method(self):
|
||||
pass
|
6
rplugin/test/templates/expected_tags
Normal file
6
rplugin/test/templates/expected_tags
Normal file
|
@ -0,0 +1,6 @@
|
|||
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
|
||||
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
|
||||
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
|
||||
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
|
||||
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
|
||||
!_TAG_PROGRAM_VERSION 0.0.0 /4f741b9/
|
|
@ -1,14 +1,20 @@
|
|||
import unittest
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import MagicMock
|
||||
from pyfakefs import fake_filesystem_unittest
|
||||
import neovim
|
||||
import os
|
||||
|
||||
from python3.neotags import NeotagsPlugin
|
||||
|
||||
|
||||
class TestNeotagsPlugin(unittest.TestCase):
|
||||
class TestNeotagsPlugin(fake_filesystem_unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.templates_dirname = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'templates'
|
||||
)
|
||||
self.setUpPyfakefs()
|
||||
self.plugin = NeotagsPlugin(Mock(neovim.api.nvim))
|
||||
|
||||
def test_default_options(self):
|
||||
|
@ -59,3 +65,62 @@ class TestNeotagsPlugin(unittest.TestCase):
|
|||
|
||||
self.plugin.error('some message')
|
||||
self.plugin.nvim.err_write.assert_not_called()
|
||||
|
||||
def test_get_tags_file_in_same_folder(self):
|
||||
filename = '/var/data/some_file.py'
|
||||
expected_tags_filename = '/var/data/tags'
|
||||
|
||||
self.fs.CreateFile(filename)
|
||||
self.fs.CreateFile(expected_tags_filename)
|
||||
|
||||
self.assertEqual(
|
||||
expected_tags_filename,
|
||||
self.plugin.get_tags_file(filename)
|
||||
)
|
||||
|
||||
def test_get_tags_file_in_parent_folder(self):
|
||||
filename = '/var/data/some_file.py'
|
||||
expected_tags_filename = '/var/tags'
|
||||
|
||||
self.fs.CreateFile(filename)
|
||||
self.fs.CreateFile(expected_tags_filename)
|
||||
|
||||
self.assertEqual(
|
||||
expected_tags_filename,
|
||||
self.plugin.get_tags_file(filename)
|
||||
)
|
||||
|
||||
def test_get_tags_file_in_root_folder(self):
|
||||
filename = '/var/data/some_file.py'
|
||||
expected_tags_filename = '/tags'
|
||||
|
||||
self.fs.CreateFile(filename)
|
||||
self.fs.CreateFile(expected_tags_filename)
|
||||
|
||||
self.assertEqual(
|
||||
expected_tags_filename,
|
||||
self.plugin.get_tags_file(filename)
|
||||
)
|
||||
|
||||
def test_strips_existing_tags(self):
|
||||
filename = '/var/data/example.py'
|
||||
tags_file = '/var/data/tags'
|
||||
expected_tags_file = os.path.join(
|
||||
self.templates_dirname,
|
||||
'expected_tags'
|
||||
)
|
||||
|
||||
self.copyRealFile(
|
||||
os.path.join(self.templates_dirname, 'example.py'),
|
||||
os.path.join(os.path.dirname(filename), os.path.basename(filename))
|
||||
)
|
||||
self.copyRealFile(
|
||||
os.path.join(self.templates_dirname, 'tags'),
|
||||
os.path.join(
|
||||
os.path.dirname(tags_file), os.path.basename(tags_file)
|
||||
)
|
||||
)
|
||||
|
||||
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())
|
||||
|
|
Loading…
Reference in a new issue