mirror of
https://github.com/gryf/pythonhelper.git
synced 2025-12-19 12:28:16 +01:00
Bugfix and move plugin to python specific ftplugin
Move to python specific plugin (ftplugin), Fixed bug regarding empty buffer.
This commit is contained in:
146
ftplugin/python/test_pythonhelper.py
Executable file
146
ftplugin/python/test_pythonhelper.py
Executable file
@@ -0,0 +1,146 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
|
||||
class Command(object):
|
||||
def __call__(self, args):
|
||||
print(args)
|
||||
|
||||
|
||||
class Window(object):
|
||||
def __init__(self):
|
||||
self.cursor = (1, 1)
|
||||
|
||||
|
||||
class Current(object):
|
||||
def __init__(self):
|
||||
self.buffer = []
|
||||
self.window = Window()
|
||||
|
||||
|
||||
class MockVim(object):
|
||||
current = Current()
|
||||
command = Command()
|
||||
|
||||
with open('test_py_example.py') as fobj:
|
||||
BUFFER = fobj.read().split('\n')
|
||||
|
||||
|
||||
sys.modules['vim'] = vim = MockVim
|
||||
|
||||
|
||||
import pythonhelper
|
||||
|
||||
|
||||
class TestTagsHelperWithEmptyBuffer(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
vim.current.buffer = []
|
||||
|
||||
def test_get_tag(self):
|
||||
vim.current.window.cursor = (1, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 2)
|
||||
self.assertIsNone(tag)
|
||||
|
||||
|
||||
class TestTagsHelper(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
vim.current.buffer = BUFFER
|
||||
|
||||
def test_import(self):
|
||||
vim.current.window.cursor = (1, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 2)
|
||||
self.assertIsNone(tag)
|
||||
|
||||
def test_class(self):
|
||||
vim.current.window.cursor = (4, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'class')
|
||||
|
||||
vim.current.window.cursor = (6, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'class')
|
||||
|
||||
vim.current.window.cursor = (7, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'class')
|
||||
|
||||
def test_init(self):
|
||||
vim.current.window.cursor = (9, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'method')
|
||||
|
||||
vim.current.window.cursor = (11, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'method')
|
||||
|
||||
def test_method(self):
|
||||
vim.current.window.cursor = (13, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'method')
|
||||
|
||||
vim.current.window.cursor = (15, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'method')
|
||||
|
||||
vim.current.window.cursor = (24, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'method')
|
||||
|
||||
# those tests should run if we have some kind of lexer analiser, not a
|
||||
# simple py source parser.
|
||||
#
|
||||
# vim.current.window.cursor = (32, 1)
|
||||
# tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
# self.assertEqual(tag.tag_type, 'method')
|
||||
|
||||
# vim.current.window.cursor = (34, 1)
|
||||
# tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
# self.assertEqual(tag.tag_type, 'method')
|
||||
|
||||
def test_inner_function(self):
|
||||
vim.current.window.cursor = (16, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'function')
|
||||
|
||||
vim.current.window.cursor = (18, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'function')
|
||||
|
||||
vim.current.window.cursor = (22, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'function')
|
||||
|
||||
vim.current.window.cursor = (23, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'function')
|
||||
|
||||
def test_main(self):
|
||||
vim.current.window.cursor = (37, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'function')
|
||||
|
||||
vim.current.window.cursor = (38, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'function')
|
||||
|
||||
vim.current.window.cursor = (40, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertEqual(tag.tag_type, 'function')
|
||||
|
||||
def test_ifmain(self):
|
||||
vim.current.window.cursor = (41, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertIsNone(tag)
|
||||
|
||||
vim.current.window.cursor = (42, 1)
|
||||
tag = pythonhelper.PythonHelper._get_tag(1, 3)
|
||||
self.assertIsNone(tag)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user