|
@@ -3,9 +3,10 @@ from time import mktime, strptime
|
|
|
from datetime import datetime, timezone, timedelta
|
|
|
|
|
|
import pytest
|
|
|
+import sys
|
|
|
import msgpack
|
|
|
|
|
|
-from ..helpers import adjust_patterns, exclude_path, Location, format_timedelta, ExcludePattern, make_path_safe, \
|
|
|
+from ..helpers import adjust_patterns, exclude_path, Location, format_timedelta, IncludePattern, ExcludePattern, make_path_safe, \
|
|
|
prune_within, prune_split, \
|
|
|
StableDict, int_to_bigint, bigint_to_int, parse_timestamp, CompressionSpec, ChunkerParams
|
|
|
from . import BaseTestCase
|
|
@@ -178,6 +179,72 @@ class PatternTestCase(BaseTestCase):
|
|
|
['/etc/passwd', '/etc/hosts', '/var/log/messages', '/var/log/dmesg'])
|
|
|
|
|
|
|
|
|
+@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)
|
|
|
+
|
|
|
+ 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")
|
|
|
+
|
|
|
+ def testDecomposedUnicode(self):
|
|
|
+ pattern = 'ba\N{COMBINING ACUTE ACCENT}'
|
|
|
+ i = IncludePattern(pattern)
|
|
|
+ e = ExcludePattern(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")
|
|
|
+
|
|
|
+ def testInvalidUnicode(self):
|
|
|
+ pattern = str(b'ba\x80', 'latin1')
|
|
|
+ i = IncludePattern(pattern)
|
|
|
+ e = ExcludePattern(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'))
|
|
|
+
|
|
|
+
|
|
|
+@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)
|
|
|
+
|
|
|
+ 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")
|
|
|
+
|
|
|
+ def testDecomposedUnicode(self):
|
|
|
+ pattern = 'ba\N{COMBINING ACUTE ACCENT}'
|
|
|
+ i = IncludePattern(pattern)
|
|
|
+ e = ExcludePattern(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")
|
|
|
+
|
|
|
+ def testInvalidUnicode(self):
|
|
|
+ pattern = str(b'ba\x80', 'latin1')
|
|
|
+ i = IncludePattern(pattern)
|
|
|
+ e = ExcludePattern(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'))
|
|
|
+
|
|
|
+
|
|
|
def test_compression_specs():
|
|
|
with pytest.raises(ValueError):
|
|
|
CompressionSpec('')
|