[meld] test: Simplify buffer lines test with fixture usage



commit a913821b07831c21c2e69f53a40720a69cb73236
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Aug 3 07:57:34 2021 +1000

    test: Simplify buffer lines test with fixture usage
    
    We're about to need more of these.

 test/test_buffer_lines.py | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/test/test_buffer_lines.py b/test/test_buffer_lines.py
index 73b096a3..f8b1acd8 100644
--- a/test/test_buffer_lines.py
+++ b/test/test_buffer_lines.py
@@ -19,6 +19,20 @@ text = ("""0
 """)
 
 
+@pytest.fixture(scope='module', autouse=True)
+def mock_bind_settings():
+    with mock.patch('meld.meldbuffer.bind_settings', mock.DEFAULT):
+        yield
+
+
+@pytest.fixture
+def buffer_setup():
+    buf = MeldBuffer()
+    buf.set_text(text)
+    buffer_lines = BufferLines(buf)
+    yield buf, buffer_lines
+
+
 @pytest.mark.parametrize("line_start, line_end, expected_text", [
     (0, 1, ["0"],),
     (0, 2, ["0", "1"],),
@@ -34,11 +48,8 @@ text = ("""0
     (10, 12, ["10"],),
     (11, 12, [],),
 ])
-def test_filter_text(line_start, line_end, expected_text):
-
-    with mock.patch('meld.meldbuffer.bind_settings', mock.DEFAULT):
-        buf = MeldBuffer()
-        buf.set_text(text)
+def test_meld_buffer_slicing(
+        line_start, line_end, expected_text, buffer_setup):
 
-        buffer_lines = BufferLines(buf)
-        assert buffer_lines[line_start:line_end] == expected_text
+    buffer, buffer_lines = buffer_setup
+    assert buffer_lines[line_start:line_end] == expected_text


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]