Skip to content

Commit

Permalink
Merge pull request #328 from blueyed/repr
Browse files Browse the repository at this point in the history
Add Buffer.__repr__ and Window.__repr__
  • Loading branch information
bfredl authored May 22, 2018
2 parents b9eff51 + 82b0109 commit 3777747
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions neovim/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ def __init__(self, session, code_data):
self.options = RemoteMap(self, self._api_prefix + 'get_option',
self._api_prefix + 'set_option')

def __repr__(self):
"""Get text representation of the object."""
return '<%s(handle=%r)>' % (
self.__class__.__name__,
self.handle,
)

def __eq__(self, other):
"""Return True if `self` and `other` are the same object."""
return (hasattr(other, 'code_data') and
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

extras_require = {
'pyuv': ['pyuv>=1.0.0'],
'test': tests_require,
}

if os.name == 'nt':
Expand Down
4 changes: 4 additions & 0 deletions test/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from neovim.compat import IS_PYTHON3


def test_repr(vim):
assert repr(vim.current.buffer) == "<Buffer(handle=2)>"


def test_get_length(vim):
assert len(vim.current.buffer) == 1
vim.current.buffer.append('line')
Expand Down
4 changes: 4 additions & 0 deletions test/test_tabpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ def test_number(vim):
assert vim.current.tabpage.number == curnum + 1
vim.command('tabnew')
assert vim.current.tabpage.number == curnum + 2


def test_repr(vim):
assert repr(vim.current.tabpage) == "<Tabpage(handle=2)>"
4 changes: 4 additions & 0 deletions test/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ def test_handle(vim):
assert hnd1 != hnd2 != hnd3
vim.command('wincmd w')
assert vim.current.window.handle == hnd1


def test_repr(vim):
assert repr(vim.current.window) == "<Window(handle=1001)>"

0 comments on commit 3777747

Please sign in to comment.