Skip to content

Commit 3777747

Browse files
authored
Merge pull request neovim#328 from blueyed/repr
Add Buffer.__repr__ and Window.__repr__
2 parents b9eff51 + 82b0109 commit 3777747

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

neovim/api/common.py

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def __init__(self, session, code_data):
3030
self.options = RemoteMap(self, self._api_prefix + 'get_option',
3131
self._api_prefix + 'set_option')
3232

33+
def __repr__(self):
34+
"""Get text representation of the object."""
35+
return '<%s(handle=%r)>' % (
36+
self.__class__.__name__,
37+
self.handle,
38+
)
39+
3340
def __eq__(self, other):
3441
"""Return True if `self` and `other` are the same object."""
3542
return (hasattr(other, 'code_data') and

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
extras_require = {
1616
'pyuv': ['pyuv>=1.0.0'],
17+
'test': tests_require,
1718
}
1819

1920
if os.name == 'nt':

test/test_buffer.py

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from neovim.compat import IS_PYTHON3
44

55

6+
def test_repr(vim):
7+
assert repr(vim.current.buffer) == "<Buffer(handle=2)>"
8+
9+
610
def test_get_length(vim):
711
assert len(vim.current.buffer) == 1
812
vim.current.buffer.append('line')

test/test_tabpage.py

+4
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ def test_number(vim):
2828
assert vim.current.tabpage.number == curnum + 1
2929
vim.command('tabnew')
3030
assert vim.current.tabpage.number == curnum + 2
31+
32+
33+
def test_repr(vim):
34+
assert repr(vim.current.tabpage) == "<Tabpage(handle=2)>"

test/test_window.py

+4
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,7 @@ def test_handle(vim):
100100
assert hnd1 != hnd2 != hnd3
101101
vim.command('wincmd w')
102102
assert vim.current.window.handle == hnd1
103+
104+
105+
def test_repr(vim):
106+
assert repr(vim.current.window) == "<Window(handle=1001)>"

0 commit comments

Comments
 (0)