[meld] test: Add a new minimal test for shell-based filter matching



commit 555c22cda06824adb79564f84b44e54ffeb564c3
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Oct 28 07:26:28 2018 +1000

    test: Add a new minimal test for shell-based filter matching

 test/test_filters.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
---
diff --git a/test/test_filters.py b/test/test_filters.py
new file mode 100644
index 00000000..403c39b8
--- /dev/null
+++ b/test/test_filters.py
@@ -0,0 +1,28 @@
+
+import pytest
+
+
+@pytest.mark.parametrize("patterns,filename,expected_match", [
+    ([r'*.csv'], 'foo.csv', True),
+    ([r'*.cvs'], 'foo.csv', False),
+    ([r'*.csv *.xml'], 'foo.csv', True),
+    ([r'*.csv *.xml'], 'foo.xml', True),
+    ([r'*.csv', r'*.xml'], 'foo.csv', True),
+    ([r'*.csv', r'*.xml'], 'foo.xml', True),
+    ([r'*.csv', r'*.xml'], 'dumbtest', False),
+    ([r'thing*csv'], 'thingcsv', True),
+    ([r'thing*csv'], 'thingwhatevercsv', True),
+    ([r'thing*csv'], 'csvthing', False),
+])
+def test_file_filters(patterns, filename, expected_match):
+    from meld.filters import FilterEntry
+
+    filters = [
+        FilterEntry.new_from_gsetting(("name", True, p), FilterEntry.SHELL)
+        for p in patterns
+    ]
+
+    # All of the dirdiff logic is "does this match any filter", so
+    # that's what we test here, even if it looks a bit weird.
+    match = any(f.filter.match(filename) for f in filters)
+    assert match == expected_match


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