mirror of
https://github.com/gryf/pythonhelper.git
synced 2025-12-18 12:00:27 +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:
@@ -151,7 +151,11 @@ class PythonHelper(object):
|
|||||||
line_number = vim.current.window.cursor[0] - 1
|
line_number = vim.current.window.cursor[0] - 1
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = vim.current.buffer[line_number]
|
try:
|
||||||
|
line = vim.current.buffer[line_number]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
line_indent = len(RE_INDENT.match(line).group(1))
|
line_indent = len(RE_INDENT.match(line).group(1))
|
||||||
if line.strip():
|
if line.strip():
|
||||||
break
|
break
|
||||||
@@ -17,8 +17,7 @@ class Window(object):
|
|||||||
|
|
||||||
class Current(object):
|
class Current(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
with open('test_py_example.py') as fobj:
|
self.buffer = []
|
||||||
self.buffer = fobj.read().split('\n')
|
|
||||||
self.window = Window()
|
self.window = Window()
|
||||||
|
|
||||||
|
|
||||||
@@ -26,6 +25,9 @@ class MockVim(object):
|
|||||||
current = Current()
|
current = Current()
|
||||||
command = Command()
|
command = Command()
|
||||||
|
|
||||||
|
with open('test_py_example.py') as fobj:
|
||||||
|
BUFFER = fobj.read().split('\n')
|
||||||
|
|
||||||
|
|
||||||
sys.modules['vim'] = vim = MockVim
|
sys.modules['vim'] = vim = MockVim
|
||||||
|
|
||||||
@@ -33,8 +35,22 @@ sys.modules['vim'] = vim = MockVim
|
|||||||
import pythonhelper
|
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):
|
class TestTagsHelper(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
vim.current.buffer = BUFFER
|
||||||
|
|
||||||
def test_import(self):
|
def test_import(self):
|
||||||
vim.current.window.cursor = (1, 1)
|
vim.current.window.cursor = (1, 1)
|
||||||
tag = pythonhelper.PythonHelper._get_tag(1, 2)
|
tag = pythonhelper.PythonHelper._get_tag(1, 2)
|
||||||
Reference in New Issue
Block a user