mirror of
https://github.com/gryf/pythonhelper.git
synced 2025-12-19 12:28:16 +01:00
Added tests for pythonhelper
This commit is contained in:
42
plugin/test_py_example.py
Normal file
42
plugin/test_py_example.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class Foo(object):
|
||||||
|
"""Some doc"""
|
||||||
|
CLASS_ATTR = {"dict": 1,
|
||||||
|
"bla": "foobar"}
|
||||||
|
|
||||||
|
def __init__(self, arg):
|
||||||
|
"""initializaion"""
|
||||||
|
self.arg = arg
|
||||||
|
|
||||||
|
def method(self, x, y):
|
||||||
|
"""very important method"""
|
||||||
|
|
||||||
|
def inner_funtion(x, y):
|
||||||
|
for i in y:
|
||||||
|
x = x + i
|
||||||
|
|
||||||
|
result = y[:]
|
||||||
|
result.append(x)
|
||||||
|
return result
|
||||||
|
|
||||||
|
result = None
|
||||||
|
result2 = """\
|
||||||
|
multiline
|
||||||
|
string
|
||||||
|
the
|
||||||
|
annoying
|
||||||
|
bastard"""
|
||||||
|
|
||||||
|
if self.arg < 100:
|
||||||
|
result = inner_funtion(x, y)
|
||||||
|
|
||||||
|
return result if result else result2
|
||||||
|
|
||||||
|
def main():
|
||||||
|
instance = Foo(10)
|
||||||
|
print(os.path.curdir, instance.method(2, [1, 2, 3]))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
133
plugin/test_pythonhelper.py
Executable file
133
plugin/test_pythonhelper.py
Executable file
@@ -0,0 +1,133 @@
|
|||||||
|
#!/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 = (5, 13) # class
|
||||||
|
# self.cursor = (8, 13) # class
|
||||||
|
# self.cursor = (12, 13) # inner function
|
||||||
|
# self.cursor = (22, 13) # method
|
||||||
|
# self.cursor = (30, 13) # function
|
||||||
|
# self.cursor = (36, 13) # function
|
||||||
|
|
||||||
|
|
||||||
|
class Current(object):
|
||||||
|
def __init__(self):
|
||||||
|
with open('test_py_example.py') as fobj:
|
||||||
|
self.buffer = fobj.read().split('\n')
|
||||||
|
self.window = Window()
|
||||||
|
|
||||||
|
|
||||||
|
class MockVim(object):
|
||||||
|
current = Current()
|
||||||
|
command = Command()
|
||||||
|
|
||||||
|
|
||||||
|
sys.modules['vim'] = vim = MockVim
|
||||||
|
|
||||||
|
import pythonhelper
|
||||||
|
|
||||||
|
|
||||||
|
class TestTagsHelper(unittest.TestCase):
|
||||||
|
|
||||||
|
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