From 58ff62f42a708713eab2b6dcf388f805df4d1938 Mon Sep 17 00:00:00 2001 From: Noel Evans Date: Sat, 22 Jun 2019 02:38:28 +0100 Subject: [PATCH] python2: fix buffer inequality operation #400 Fix #398 Also fix warning in test_buffer.py:96: DeprecationWarning: invalid escape sequence \s assert vim.options['define'] == '^\s*#\s*define' --- pynvim/api/buffer.py | 6 ++++++ test/test_buffer.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pynvim/api/buffer.py b/pynvim/api/buffer.py index 786e322c..d46510d7 100644 --- a/pynvim/api/buffer.py +++ b/pynvim/api/buffer.py @@ -83,6 +83,12 @@ def __delitem__(self, idx): """ self.__setitem__(idx, None) + def __ne__(self, other): + """ Test inequality of Buffers. + + Necessary for Python 2 compatibility """ + return not self.__eq__(other) + def append(self, lines, index=-1): """Append a string or list of lines to the buffer.""" if isinstance(lines, (basestring, bytes)): diff --git a/test/test_buffer.py b/test/test_buffer.py index c0556f63..6a2780a9 100644 --- a/test/test_buffer.py +++ b/test/test_buffer.py @@ -93,7 +93,7 @@ def test_options(vim): vim.current.buffer.options['define'] = 'test' assert vim.current.buffer.options['define'] == 'test' # Doesn't change the global value - assert vim.options['define'] == '^\s*#\s*define' + assert vim.options['define'] == r'^\s*#\s*define' def test_number(vim): @@ -172,3 +172,9 @@ def test_update_highlights(vim): vim.current.buffer[:] = ['a', 'b', 'c'] src_id = vim.new_highlight_source() vim.current.buffer.update_highlights(src_id, [["Comment", 0, 0, -1], ("String", 1, 0, 1)], clear=True, async_=False) + + +def test_buffer_inequality(vim): + b = vim.current.buffer + assert not (b != vim.current.buffer) +