瀏覽代碼

Refactor Unicode pattern tests

The unit tests for Unicode in path patterns contained a lot of
unnecessary duplication. One set of duplication was for Mac OS X (also
known as Darwin) as it normalizes Unicode in paths to NFD. Then each
test case was repeated for every type of pattern.

With this change the tests become parametrized using py.test. The
duplicated code has been removed.
Michael Hanselmann 9 年之前
父節點
當前提交
2c7ab8595d
共有 1 個文件被更改,包括 27 次插入82 次删除
  1. 27 82
      borg/testsuite/helpers.py

+ 27 - 82
borg/testsuite/helpers.py

@@ -233,88 +233,33 @@ def test_regex_pattern():
     assert not ExcludeRegex(r"^\\$").match("/")
     assert not ExcludeRegex(r"^\\$").match("/")
 
 
 
 
-@pytest.mark.skipif(sys.platform in ('darwin',), reason='all but OS X test')
-class PatternNonAsciiTestCase(BaseTestCase):
-    def testComposedUnicode(self):
-        pattern = 'b\N{LATIN SMALL LETTER A WITH ACUTE}'
-        i = IncludePattern(pattern)
-        e = ExcludePattern(pattern)
-        er = ExcludeRegex("^{}/foo$".format(pattern))
-
-        assert i.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert not i.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-        assert e.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert not e.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-        assert er.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert not er.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-
-    def testDecomposedUnicode(self):
-        pattern = 'ba\N{COMBINING ACUTE ACCENT}'
-        i = IncludePattern(pattern)
-        e = ExcludePattern(pattern)
-        er = ExcludeRegex("^{}/foo$".format(pattern))
-
-        assert not i.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert i.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-        assert not e.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert e.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-        assert not er.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert er.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-
-    def testInvalidUnicode(self):
-        pattern = str(b'ba\x80', 'latin1')
-        i = IncludePattern(pattern)
-        e = ExcludePattern(pattern)
-        er = ExcludeRegex("^{}/foo$".format(pattern))
-
-        assert not i.match("ba/foo")
-        assert i.match(str(b"ba\x80/foo", 'latin1'))
-        assert not e.match("ba/foo")
-        assert e.match(str(b"ba\x80/foo", 'latin1'))
-        assert not er.match("ba/foo")
-        assert er.match(str(b"ba\x80/foo", 'latin1'))
-
-
-@pytest.mark.skipif(sys.platform not in ('darwin',), reason='OS X test')
-class OSXPatternNormalizationTestCase(BaseTestCase):
-    def testComposedUnicode(self):
-        pattern = 'b\N{LATIN SMALL LETTER A WITH ACUTE}'
-        i = IncludePattern(pattern)
-        e = ExcludePattern(pattern)
-        er = ExcludeRegex("^{}/foo$".format(pattern))
-
-        assert i.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert i.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-        assert e.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert e.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-        assert er.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert er.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-
-    def testDecomposedUnicode(self):
-        pattern = 'ba\N{COMBINING ACUTE ACCENT}'
-        i = IncludePattern(pattern)
-        e = ExcludePattern(pattern)
-        er = ExcludeRegex("^{}/foo$".format(pattern))
-
-        assert i.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert i.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-        assert e.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert e.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-        assert er.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
-        assert er.match("ba\N{COMBINING ACUTE ACCENT}/foo")
-
-    def testInvalidUnicode(self):
-        pattern = str(b'ba\x80', 'latin1')
-        i = IncludePattern(pattern)
-        e = ExcludePattern(pattern)
-        er = ExcludeRegex("^{}/foo$".format(pattern))
-
-        assert not i.match("ba/foo")
-        assert i.match(str(b"ba\x80/foo", 'latin1'))
-        assert not e.match("ba/foo")
-        assert e.match(str(b"ba\x80/foo", 'latin1'))
-        assert not er.match("ba/foo")
-        assert er.match(str(b"ba\x80/foo", 'latin1'))
+def use_normalized_unicode():
+    return sys.platform in ("darwin",)
+
+
+def _make_test_patterns(pattern):
+    return [IncludePattern(pattern),
+            ExcludePattern(pattern),
+            ExcludeRegex("^{}/foo$".format(pattern)),
+            ]
+
+
+@pytest.mark.parametrize("pattern", _make_test_patterns("b\N{LATIN SMALL LETTER A WITH ACUTE}"))
+def test_composed_unicode_pattern(pattern):
+    assert pattern.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo")
+    assert pattern.match("ba\N{COMBINING ACUTE ACCENT}/foo") == use_normalized_unicode()
+
+
+@pytest.mark.parametrize("pattern", _make_test_patterns("ba\N{COMBINING ACUTE ACCENT}"))
+def test_decomposed_unicode_pattern(pattern):
+    assert pattern.match("b\N{LATIN SMALL LETTER A WITH ACUTE}/foo") == use_normalized_unicode()
+    assert pattern.match("ba\N{COMBINING ACUTE ACCENT}/foo")
+
+
+@pytest.mark.parametrize("pattern", _make_test_patterns(str(b"ba\x80", "latin1")))
+def test_invalid_unicode_pattern(pattern):
+    assert not pattern.match("ba/foo")
+    assert pattern.match(str(b"ba\x80/foo", "latin1"))
 
 
 
 
 @pytest.mark.parametrize("lines, expected", [
 @pytest.mark.parametrize("lines, expected", [