Done with
python3 contrib/byteify-strings.py tests/test-match.py -i
- skip-blame just bytes prefixes
hg-reviewers |
Done with
python3 contrib/byteify-strings.py tests/test-match.py -i
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
from __future__ import absolute_import | from __future__ import absolute_import | ||||
import unittest | import unittest | ||||
import silenttestrunner | import silenttestrunner | ||||
from mercurial import ( | from mercurial import ( | ||||
match as matchmod, | match as matchmod, | ||||
util, | util, | ||||
) | ) | ||||
class BaseMatcherTests(unittest.TestCase): | class BaseMatcherTests(unittest.TestCase): | ||||
def testVisitdir(self): | def testVisitdir(self): | ||||
m = matchmod.basematcher('', '') | m = matchmod.basematcher(b'', b'') | ||||
self.assertTrue(m.visitdir('.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertTrue(m.visitdir('dir')) | self.assertTrue(m.visitdir(b'dir')) | ||||
def testVisitchildrenset(self): | def testVisitchildrenset(self): | ||||
m = matchmod.basematcher('', '') | m = matchmod.basematcher(b'', b'') | ||||
self.assertEqual(m.visitchildrenset('.'), 'this') | self.assertEqual(m.visitchildrenset(b'.'), b'this') | ||||
self.assertEqual(m.visitchildrenset('dir'), 'this') | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||||
class AlwaysMatcherTests(unittest.TestCase): | class AlwaysMatcherTests(unittest.TestCase): | ||||
def testVisitdir(self): | def testVisitdir(self): | ||||
m = matchmod.alwaysmatcher('', '') | m = matchmod.alwaysmatcher(b'', b'') | ||||
self.assertEqual(m.visitdir('.'), 'all') | self.assertEqual(m.visitdir(b'.'), b'all') | ||||
self.assertEqual(m.visitdir('dir'), 'all') | self.assertEqual(m.visitdir(b'dir'), b'all') | ||||
def testVisitchildrenset(self): | def testVisitchildrenset(self): | ||||
m = matchmod.alwaysmatcher('', '') | m = matchmod.alwaysmatcher(b'', b'') | ||||
self.assertEqual(m.visitchildrenset('.'), 'all') | self.assertEqual(m.visitchildrenset(b'.'), b'all') | ||||
self.assertEqual(m.visitchildrenset('dir'), 'all') | self.assertEqual(m.visitchildrenset(b'dir'), b'all') | ||||
class NeverMatcherTests(unittest.TestCase): | class NeverMatcherTests(unittest.TestCase): | ||||
def testVisitdir(self): | def testVisitdir(self): | ||||
m = matchmod.nevermatcher('', '') | m = matchmod.nevermatcher(b'', b'') | ||||
self.assertFalse(m.visitdir('.')) | self.assertFalse(m.visitdir(b'.')) | ||||
self.assertFalse(m.visitdir('dir')) | self.assertFalse(m.visitdir(b'dir')) | ||||
def testVisitchildrenset(self): | def testVisitchildrenset(self): | ||||
m = matchmod.nevermatcher('', '') | m = matchmod.nevermatcher(b'', b'') | ||||
self.assertEqual(m.visitchildrenset('.'), set()) | self.assertEqual(m.visitchildrenset(b'.'), set()) | ||||
self.assertEqual(m.visitchildrenset('dir'), set()) | self.assertEqual(m.visitchildrenset(b'dir'), set()) | ||||
class PredicateMatcherTests(unittest.TestCase): | class PredicateMatcherTests(unittest.TestCase): | ||||
# predicatematcher does not currently define either of these methods, so | # predicatematcher does not currently define either of these methods, so | ||||
# this is equivalent to BaseMatcherTests. | # this is equivalent to BaseMatcherTests. | ||||
def testVisitdir(self): | def testVisitdir(self): | ||||
m = matchmod.predicatematcher('', '', lambda *a: False) | m = matchmod.predicatematcher(b'', b'', lambda *a: False) | ||||
self.assertTrue(m.visitdir('.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertTrue(m.visitdir('dir')) | self.assertTrue(m.visitdir(b'dir')) | ||||
def testVisitchildrenset(self): | def testVisitchildrenset(self): | ||||
m = matchmod.predicatematcher('', '', lambda *a: False) | m = matchmod.predicatematcher(b'', b'', lambda *a: False) | ||||
self.assertEqual(m.visitchildrenset('.'), 'this') | self.assertEqual(m.visitchildrenset(b'.'), b'this') | ||||
self.assertEqual(m.visitchildrenset('dir'), 'this') | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||||
class PatternMatcherTests(unittest.TestCase): | class PatternMatcherTests(unittest.TestCase): | ||||
def testVisitdirPrefix(self): | def testVisitdirPrefix(self): | ||||
m = matchmod.match('x', '', patterns=['path:dir/subdir']) | m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir']) | ||||
assert isinstance(m, matchmod.patternmatcher) | assert isinstance(m, matchmod.patternmatcher) | ||||
self.assertTrue(m.visitdir('.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertTrue(m.visitdir('dir')) | self.assertTrue(m.visitdir(b'dir')) | ||||
self.assertEqual(m.visitdir('dir/subdir'), 'all') | self.assertEqual(m.visitdir(b'dir/subdir'), b'all') | ||||
# OPT: This should probably be 'all' if its parent is? | # OPT: This should probably be 'all' if its parent is? | ||||
self.assertTrue(m.visitdir('dir/subdir/x')) | self.assertTrue(m.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(m.visitdir('folder')) | self.assertFalse(m.visitdir(b'folder')) | ||||
def testVisitchildrensetPrefix(self): | def testVisitchildrensetPrefix(self): | ||||
m = matchmod.match('x', '', patterns=['path:dir/subdir']) | m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir']) | ||||
assert isinstance(m, matchmod.patternmatcher) | assert isinstance(m, matchmod.patternmatcher) | ||||
self.assertEqual(m.visitchildrenset('.'), 'this') | self.assertEqual(m.visitchildrenset(b'.'), b'this') | ||||
self.assertEqual(m.visitchildrenset('dir'), 'this') | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||||
self.assertEqual(m.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') | ||||
# OPT: This should probably be 'all' if its parent is? | # OPT: This should probably be 'all' if its parent is? | ||||
self.assertEqual(m.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
self.assertEqual(m.visitchildrenset('folder'), set()) | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
def testVisitdirRootfilesin(self): | def testVisitdirRootfilesin(self): | ||||
m = matchmod.match('x', '', patterns=['rootfilesin:dir/subdir']) | m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir']) | ||||
assert isinstance(m, matchmod.patternmatcher) | assert isinstance(m, matchmod.patternmatcher) | ||||
self.assertTrue(m.visitdir('.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertFalse(m.visitdir('dir/subdir/x')) | self.assertFalse(m.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(m.visitdir('folder')) | self.assertFalse(m.visitdir(b'folder')) | ||||
# FIXME: These should probably be True. | # FIXME: These should probably be True. | ||||
self.assertFalse(m.visitdir('dir')) | self.assertFalse(m.visitdir(b'dir')) | ||||
self.assertFalse(m.visitdir('dir/subdir')) | self.assertFalse(m.visitdir(b'dir/subdir')) | ||||
def testVisitchildrensetRootfilesin(self): | def testVisitchildrensetRootfilesin(self): | ||||
m = matchmod.match('x', '', patterns=['rootfilesin:dir/subdir']) | m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir']) | ||||
assert isinstance(m, matchmod.patternmatcher) | assert isinstance(m, matchmod.patternmatcher) | ||||
self.assertEqual(m.visitchildrenset('.'), 'this') | self.assertEqual(m.visitchildrenset(b'.'), b'this') | ||||
self.assertEqual(m.visitchildrenset('dir/subdir/x'), set()) | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | ||||
self.assertEqual(m.visitchildrenset('folder'), set()) | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
# FIXME: These should probably be {'subdir'} and 'this', respectively, | # FIXME: These should probably be {'subdir'} and 'this', respectively, | ||||
# or at least 'this' and 'this'. | # or at least 'this' and 'this'. | ||||
self.assertEqual(m.visitchildrenset('dir'), set()) | self.assertEqual(m.visitchildrenset(b'dir'), set()) | ||||
self.assertEqual(m.visitchildrenset('dir/subdir'), set()) | self.assertEqual(m.visitchildrenset(b'dir/subdir'), set()) | ||||
def testVisitdirGlob(self): | def testVisitdirGlob(self): | ||||
m = matchmod.match('x', '', patterns=['glob:dir/z*']) | m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*']) | ||||
assert isinstance(m, matchmod.patternmatcher) | assert isinstance(m, matchmod.patternmatcher) | ||||
self.assertTrue(m.visitdir('.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertTrue(m.visitdir('dir')) | self.assertTrue(m.visitdir(b'dir')) | ||||
self.assertFalse(m.visitdir('folder')) | self.assertFalse(m.visitdir(b'folder')) | ||||
# OPT: these should probably be False. | # OPT: these should probably be False. | ||||
self.assertTrue(m.visitdir('dir/subdir')) | self.assertTrue(m.visitdir(b'dir/subdir')) | ||||
self.assertTrue(m.visitdir('dir/subdir/x')) | self.assertTrue(m.visitdir(b'dir/subdir/x')) | ||||
def testVisitchildrensetGlob(self): | def testVisitchildrensetGlob(self): | ||||
m = matchmod.match('x', '', patterns=['glob:dir/z*']) | m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*']) | ||||
assert isinstance(m, matchmod.patternmatcher) | assert isinstance(m, matchmod.patternmatcher) | ||||
self.assertEqual(m.visitchildrenset('.'), 'this') | self.assertEqual(m.visitchildrenset(b'.'), b'this') | ||||
self.assertEqual(m.visitchildrenset('folder'), set()) | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(m.visitchildrenset('dir'), 'this') | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||||
# OPT: these should probably be set(). | # OPT: these should probably be set(). | ||||
self.assertEqual(m.visitchildrenset('dir/subdir'), 'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | ||||
self.assertEqual(m.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
class IncludeMatcherTests(unittest.TestCase): | class IncludeMatcherTests(unittest.TestCase): | ||||
def testVisitdirPrefix(self): | def testVisitdirPrefix(self): | ||||
m = matchmod.match('x', '', include=['path:dir/subdir']) | m = matchmod.match(b'x', b'', include=[b'path:dir/subdir']) | ||||
assert isinstance(m, matchmod.includematcher) | assert isinstance(m, matchmod.includematcher) | ||||
self.assertTrue(m.visitdir('.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertTrue(m.visitdir('dir')) | self.assertTrue(m.visitdir(b'dir')) | ||||
self.assertEqual(m.visitdir('dir/subdir'), 'all') | self.assertEqual(m.visitdir(b'dir/subdir'), b'all') | ||||
# OPT: This should probably be 'all' if its parent is? | # OPT: This should probably be 'all' if its parent is? | ||||
self.assertTrue(m.visitdir('dir/subdir/x')) | self.assertTrue(m.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(m.visitdir('folder')) | self.assertFalse(m.visitdir(b'folder')) | ||||
def testVisitchildrensetPrefix(self): | def testVisitchildrensetPrefix(self): | ||||
m = matchmod.match('x', '', include=['path:dir/subdir']) | m = matchmod.match(b'x', b'', include=[b'path:dir/subdir']) | ||||
assert isinstance(m, matchmod.includematcher) | assert isinstance(m, matchmod.includematcher) | ||||
self.assertEqual(m.visitchildrenset('.'), {'dir'}) | self.assertEqual(m.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(m.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(m.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') | ||||
# OPT: This should probably be 'all' if its parent is? | # OPT: This should probably be 'all' if its parent is? | ||||
self.assertEqual(m.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
self.assertEqual(m.visitchildrenset('folder'), set()) | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
def testVisitdirRootfilesin(self): | def testVisitdirRootfilesin(self): | ||||
m = matchmod.match('x', '', include=['rootfilesin:dir/subdir']) | m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir']) | ||||
assert isinstance(m, matchmod.includematcher) | assert isinstance(m, matchmod.includematcher) | ||||
self.assertTrue(m.visitdir('.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertTrue(m.visitdir('dir')) | self.assertTrue(m.visitdir(b'dir')) | ||||
self.assertTrue(m.visitdir('dir/subdir')) | self.assertTrue(m.visitdir(b'dir/subdir')) | ||||
self.assertFalse(m.visitdir('dir/subdir/x')) | self.assertFalse(m.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(m.visitdir('folder')) | self.assertFalse(m.visitdir(b'folder')) | ||||
def testVisitchildrensetRootfilesin(self): | def testVisitchildrensetRootfilesin(self): | ||||
m = matchmod.match('x', '', include=['rootfilesin:dir/subdir']) | m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir']) | ||||
assert isinstance(m, matchmod.includematcher) | assert isinstance(m, matchmod.includematcher) | ||||
self.assertEqual(m.visitchildrenset('.'), {'dir'}) | self.assertEqual(m.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(m.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(m.visitchildrenset('dir/subdir'), 'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | ||||
self.assertEqual(m.visitchildrenset('dir/subdir/x'), set()) | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | ||||
self.assertEqual(m.visitchildrenset('folder'), set()) | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
def testVisitdirGlob(self): | def testVisitdirGlob(self): | ||||
m = matchmod.match('x', '', include=['glob:dir/z*']) | m = matchmod.match(b'x', b'', include=[b'glob:dir/z*']) | ||||
assert isinstance(m, matchmod.includematcher) | assert isinstance(m, matchmod.includematcher) | ||||
self.assertTrue(m.visitdir('.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertTrue(m.visitdir('dir')) | self.assertTrue(m.visitdir(b'dir')) | ||||
self.assertFalse(m.visitdir('folder')) | self.assertFalse(m.visitdir(b'folder')) | ||||
# OPT: these should probably be False. | # OPT: these should probably be False. | ||||
self.assertTrue(m.visitdir('dir/subdir')) | self.assertTrue(m.visitdir(b'dir/subdir')) | ||||
self.assertTrue(m.visitdir('dir/subdir/x')) | self.assertTrue(m.visitdir(b'dir/subdir/x')) | ||||
def testVisitchildrensetGlob(self): | def testVisitchildrensetGlob(self): | ||||
m = matchmod.match('x', '', include=['glob:dir/z*']) | m = matchmod.match(b'x', b'', include=[b'glob:dir/z*']) | ||||
assert isinstance(m, matchmod.includematcher) | assert isinstance(m, matchmod.includematcher) | ||||
self.assertEqual(m.visitchildrenset('.'), {'dir'}) | self.assertEqual(m.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(m.visitchildrenset('folder'), set()) | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(m.visitchildrenset('dir'), 'this') | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||||
# OPT: these should probably be set(). | # OPT: these should probably be set(). | ||||
self.assertEqual(m.visitchildrenset('dir/subdir'), 'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | ||||
self.assertEqual(m.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
class ExactMatcherTests(unittest.TestCase): | class ExactMatcherTests(unittest.TestCase): | ||||
def testVisitdir(self): | def testVisitdir(self): | ||||
m = matchmod.match('x', '', patterns=['dir/subdir/foo.txt'], exact=True) | m = matchmod.match(b'x', b'', patterns=[b'dir/subdir/foo.txt'], | ||||
exact=True) | |||||
assert isinstance(m, matchmod.exactmatcher) | assert isinstance(m, matchmod.exactmatcher) | ||||
self.assertTrue(m.visitdir('.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertTrue(m.visitdir('dir')) | self.assertTrue(m.visitdir(b'dir')) | ||||
self.assertTrue(m.visitdir('dir/subdir')) | self.assertTrue(m.visitdir(b'dir/subdir')) | ||||
self.assertFalse(m.visitdir('dir/subdir/foo.txt')) | self.assertFalse(m.visitdir(b'dir/subdir/foo.txt')) | ||||
self.assertFalse(m.visitdir('dir/foo')) | self.assertFalse(m.visitdir(b'dir/foo')) | ||||
self.assertFalse(m.visitdir('dir/subdir/x')) | self.assertFalse(m.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(m.visitdir('folder')) | self.assertFalse(m.visitdir(b'folder')) | ||||
def testVisitchildrenset(self): | def testVisitchildrenset(self): | ||||
m = matchmod.match('x', '', patterns=['dir/subdir/foo.txt'], exact=True) | m = matchmod.match(b'x', b'', patterns=[b'dir/subdir/foo.txt'], | ||||
exact=True) | |||||
assert isinstance(m, matchmod.exactmatcher) | assert isinstance(m, matchmod.exactmatcher) | ||||
self.assertEqual(m.visitchildrenset('.'), {'dir'}) | self.assertEqual(m.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(m.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(m.visitchildrenset('dir/subdir'), 'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | ||||
self.assertEqual(m.visitchildrenset('dir/subdir/x'), set()) | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | ||||
self.assertEqual(m.visitchildrenset('dir/subdir/foo.txt'), set()) | self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set()) | ||||
self.assertEqual(m.visitchildrenset('folder'), set()) | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
class DifferenceMatcherTests(unittest.TestCase): | class DifferenceMatcherTests(unittest.TestCase): | ||||
def testVisitdirM2always(self): | def testVisitdirM2always(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.alwaysmatcher('', '') | m2 = matchmod.alwaysmatcher(b'', b'') | ||||
dm = matchmod.differencematcher(m1, m2) | dm = matchmod.differencematcher(m1, m2) | ||||
# dm should be equivalent to a nevermatcher. | # dm should be equivalent to a nevermatcher. | ||||
self.assertFalse(dm.visitdir('.')) | self.assertFalse(dm.visitdir(b'.')) | ||||
self.assertFalse(dm.visitdir('dir')) | self.assertFalse(dm.visitdir(b'dir')) | ||||
self.assertFalse(dm.visitdir('dir/subdir')) | self.assertFalse(dm.visitdir(b'dir/subdir')) | ||||
self.assertFalse(dm.visitdir('dir/subdir/z')) | self.assertFalse(dm.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(dm.visitdir('dir/foo')) | self.assertFalse(dm.visitdir(b'dir/foo')) | ||||
self.assertFalse(dm.visitdir('dir/subdir/x')) | self.assertFalse(dm.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(dm.visitdir('folder')) | self.assertFalse(dm.visitdir(b'folder')) | ||||
def testVisitchildrensetM2always(self): | def testVisitchildrensetM2always(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.alwaysmatcher('', '') | m2 = matchmod.alwaysmatcher(b'', b'') | ||||
dm = matchmod.differencematcher(m1, m2) | dm = matchmod.differencematcher(m1, m2) | ||||
# dm should be equivalent to a nevermatcher. | # dm should be equivalent to a nevermatcher. | ||||
self.assertEqual(dm.visitchildrenset('.'), set()) | self.assertEqual(dm.visitchildrenset(b'.'), set()) | ||||
self.assertEqual(dm.visitchildrenset('dir'), set()) | self.assertEqual(dm.visitchildrenset(b'dir'), set()) | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir'), set()) | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir/z'), set()) | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(dm.visitchildrenset('dir/foo'), set()) | self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir/x'), set()) | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), set()) | ||||
self.assertEqual(dm.visitchildrenset('folder'), set()) | self.assertEqual(dm.visitchildrenset(b'folder'), set()) | ||||
def testVisitdirM2never(self): | def testVisitdirM2never(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.nevermatcher('', '') | m2 = matchmod.nevermatcher(b'', b'') | ||||
dm = matchmod.differencematcher(m1, m2) | dm = matchmod.differencematcher(m1, m2) | ||||
# dm should be equivalent to a alwaysmatcher. OPT: if m2 is a | # dm should be equivalent to a alwaysmatcher. OPT: if m2 is a | ||||
# nevermatcher, we could return 'all' for these. | # nevermatcher, we could return 'all' for these. | ||||
# | # | ||||
# We're testing Equal-to-True instead of just 'assertTrue' since | # We're testing Equal-to-True instead of just 'assertTrue' since | ||||
# assertTrue does NOT verify that it's a bool, just that it's truthy. | # assertTrue does NOT verify that it's a bool, just that it's truthy. | ||||
# While we may want to eventually make these return 'all', they should | # While we may want to eventually make these return 'all', they should | ||||
# not currently do so. | # not currently do so. | ||||
self.assertEqual(dm.visitdir('.'), True) | self.assertEqual(dm.visitdir(b'.'), True) | ||||
self.assertEqual(dm.visitdir('dir'), True) | self.assertEqual(dm.visitdir(b'dir'), True) | ||||
self.assertEqual(dm.visitdir('dir/subdir'), True) | self.assertEqual(dm.visitdir(b'dir/subdir'), True) | ||||
self.assertEqual(dm.visitdir('dir/subdir/z'), True) | self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) | ||||
self.assertEqual(dm.visitdir('dir/foo'), True) | self.assertEqual(dm.visitdir(b'dir/foo'), True) | ||||
self.assertEqual(dm.visitdir('dir/subdir/x'), True) | self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) | ||||
self.assertEqual(dm.visitdir('folder'), True) | self.assertEqual(dm.visitdir(b'folder'), True) | ||||
def testVisitchildrensetM2never(self): | def testVisitchildrensetM2never(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.nevermatcher('', '') | m2 = matchmod.nevermatcher(b'', b'') | ||||
dm = matchmod.differencematcher(m1, m2) | dm = matchmod.differencematcher(m1, m2) | ||||
# dm should be equivalent to a alwaysmatcher. | # dm should be equivalent to a alwaysmatcher. | ||||
self.assertEqual(dm.visitchildrenset('.'), 'all') | self.assertEqual(dm.visitchildrenset(b'.'), b'all') | ||||
self.assertEqual(dm.visitchildrenset('dir'), 'all') | self.assertEqual(dm.visitchildrenset(b'dir'), b'all') | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir/z'), 'all') | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(dm.visitchildrenset('dir/foo'), 'all') | self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir/x'), 'all') | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(dm.visitchildrenset('folder'), 'all') | self.assertEqual(dm.visitchildrenset(b'folder'), b'all') | ||||
def testVisitdirM2SubdirPrefix(self): | def testVisitdirM2SubdirPrefix(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.match('', '', patterns=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | ||||
dm = matchmod.differencematcher(m1, m2) | dm = matchmod.differencematcher(m1, m2) | ||||
self.assertEqual(dm.visitdir('.'), True) | self.assertEqual(dm.visitdir(b'.'), True) | ||||
self.assertEqual(dm.visitdir('dir'), True) | self.assertEqual(dm.visitdir(b'dir'), True) | ||||
self.assertFalse(dm.visitdir('dir/subdir')) | self.assertFalse(dm.visitdir(b'dir/subdir')) | ||||
# OPT: We should probably return False for these; we don't because | # OPT: We should probably return False for these; we don't because | ||||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just True. | # an 'all' pattern, just True. | ||||
self.assertEqual(dm.visitdir('dir/subdir/z'), True) | self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) | ||||
self.assertEqual(dm.visitdir('dir/subdir/x'), True) | self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) | ||||
# OPT: We could return 'all' for these. | # OPT: We could return 'all' for these. | ||||
self.assertEqual(dm.visitdir('dir/foo'), True) | self.assertEqual(dm.visitdir(b'dir/foo'), True) | ||||
self.assertEqual(dm.visitdir('folder'), True) | self.assertEqual(dm.visitdir(b'folder'), True) | ||||
def testVisitchildrensetM2SubdirPrefix(self): | def testVisitchildrensetM2SubdirPrefix(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.match('', '', patterns=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | ||||
dm = matchmod.differencematcher(m1, m2) | dm = matchmod.differencematcher(m1, m2) | ||||
self.assertEqual(dm.visitchildrenset('.'), 'this') | self.assertEqual(dm.visitchildrenset(b'.'), b'this') | ||||
self.assertEqual(dm.visitchildrenset('dir'), 'this') | self.assertEqual(dm.visitchildrenset(b'dir'), b'this') | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir'), set()) | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(dm.visitchildrenset('dir/foo'), 'all') | self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(dm.visitchildrenset('folder'), 'all') | self.assertEqual(dm.visitchildrenset(b'folder'), b'all') | ||||
# OPT: We should probably return set() for these; we don't because | # OPT: We should probably return set() for these; we don't because | ||||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just 'this'. | # an 'all' pattern, just 'this'. | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir/z'), 'this') | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
# We're using includematcher instead of patterns because it behaves slightly | # We're using includematcher instead of patterns because it behaves slightly | ||||
# better (giving narrower results) than patternmatcher. | # better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeIncludfe(self): | def testVisitdirIncludeIncludfe(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['rootfilesin:dir']) | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
dm = matchmod.differencematcher(m1, m2) | dm = matchmod.differencematcher(m1, m2) | ||||
self.assertEqual(dm.visitdir('.'), True) | self.assertEqual(dm.visitdir(b'.'), True) | ||||
self.assertEqual(dm.visitdir('dir'), True) | self.assertEqual(dm.visitdir(b'dir'), True) | ||||
self.assertEqual(dm.visitdir('dir/subdir'), True) | self.assertEqual(dm.visitdir(b'dir/subdir'), True) | ||||
self.assertFalse(dm.visitdir('dir/foo')) | self.assertFalse(dm.visitdir(b'dir/foo')) | ||||
self.assertFalse(dm.visitdir('folder')) | self.assertFalse(dm.visitdir(b'folder')) | ||||
# OPT: We should probably return False for these; we don't because | # OPT: We should probably return False for these; we don't because | ||||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just True. | # an 'all' pattern, just True. | ||||
self.assertEqual(dm.visitdir('dir/subdir/z'), True) | self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) | ||||
self.assertEqual(dm.visitdir('dir/subdir/x'), True) | self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) | ||||
def testVisitchildrensetIncludeInclude(self): | def testVisitchildrensetIncludeInclude(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['rootfilesin:dir']) | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
dm = matchmod.differencematcher(m1, m2) | dm = matchmod.differencematcher(m1, m2) | ||||
self.assertEqual(dm.visitchildrenset('.'), {'dir'}) | self.assertEqual(dm.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(dm.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(dm.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(dm.visitchildrenset('dir/foo'), set()) | self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(dm.visitchildrenset('folder'), set()) | self.assertEqual(dm.visitchildrenset(b'folder'), set()) | ||||
# OPT: We should probably return set() for these; we don't because | # OPT: We should probably return set() for these; we don't because | ||||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just 'this'. | # an 'all' pattern, just 'this'. | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir/z'), 'this') | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') | ||||
self.assertEqual(dm.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
class IntersectionMatcherTests(unittest.TestCase): | class IntersectionMatcherTests(unittest.TestCase): | ||||
def testVisitdirM2always(self): | def testVisitdirM2always(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.alwaysmatcher('', '') | m2 = matchmod.alwaysmatcher(b'', b'') | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
# im should be equivalent to a alwaysmatcher. | # im should be equivalent to a alwaysmatcher. | ||||
self.assertEqual(im.visitdir('.'), 'all') | self.assertEqual(im.visitdir(b'.'), b'all') | ||||
self.assertEqual(im.visitdir('dir'), 'all') | self.assertEqual(im.visitdir(b'dir'), b'all') | ||||
self.assertEqual(im.visitdir('dir/subdir'), 'all') | self.assertEqual(im.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(im.visitdir('dir/subdir/z'), 'all') | self.assertEqual(im.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(im.visitdir('dir/foo'), 'all') | self.assertEqual(im.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(im.visitdir('dir/subdir/x'), 'all') | self.assertEqual(im.visitdir(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(im.visitdir('folder'), 'all') | self.assertEqual(im.visitdir(b'folder'), b'all') | ||||
def testVisitchildrensetM2always(self): | def testVisitchildrensetM2always(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.alwaysmatcher('', '') | m2 = matchmod.alwaysmatcher(b'', b'') | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
# im should be equivalent to a alwaysmatcher. | # im should be equivalent to a alwaysmatcher. | ||||
self.assertEqual(im.visitchildrenset('.'), 'all') | self.assertEqual(im.visitchildrenset(b'.'), b'all') | ||||
self.assertEqual(im.visitchildrenset('dir'), 'all') | self.assertEqual(im.visitchildrenset(b'dir'), b'all') | ||||
self.assertEqual(im.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/z'), 'all') | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(im.visitchildrenset('dir/foo'), 'all') | self.assertEqual(im.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/x'), 'all') | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(im.visitchildrenset('folder'), 'all') | self.assertEqual(im.visitchildrenset(b'folder'), b'all') | ||||
def testVisitdirM2never(self): | def testVisitdirM2never(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.nevermatcher('', '') | m2 = matchmod.nevermatcher(b'', b'') | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
# im should be equivalent to a nevermatcher. | # im should be equivalent to a nevermatcher. | ||||
self.assertFalse(im.visitdir('.')) | self.assertFalse(im.visitdir(b'.')) | ||||
self.assertFalse(im.visitdir('dir')) | self.assertFalse(im.visitdir(b'dir')) | ||||
self.assertFalse(im.visitdir('dir/subdir')) | self.assertFalse(im.visitdir(b'dir/subdir')) | ||||
self.assertFalse(im.visitdir('dir/subdir/z')) | self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(im.visitdir('dir/foo')) | self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir('dir/subdir/x')) | self.assertFalse(im.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(im.visitdir('folder')) | self.assertFalse(im.visitdir(b'folder')) | ||||
def testVisitchildrensetM2never(self): | def testVisitchildrensetM2never(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.nevermatcher('', '') | m2 = matchmod.nevermatcher(b'', b'') | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
# im should be equivalent to a nevermqtcher. | # im should be equivalent to a nevermqtcher. | ||||
self.assertEqual(im.visitchildrenset('.'), set()) | self.assertEqual(im.visitchildrenset(b'.'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir'), set()) | self.assertEqual(im.visitchildrenset(b'dir'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/foo'), set()) | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/x'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | ||||
self.assertEqual(im.visitchildrenset('folder'), set()) | self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
def testVisitdirM2SubdirPrefix(self): | def testVisitdirM2SubdirPrefix(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.match('', '', patterns=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
self.assertEqual(im.visitdir('.'), True) | self.assertEqual(im.visitdir(b'.'), True) | ||||
self.assertEqual(im.visitdir('dir'), True) | self.assertEqual(im.visitdir(b'dir'), True) | ||||
self.assertEqual(im.visitdir('dir/subdir'), 'all') | self.assertEqual(im.visitdir(b'dir/subdir'), b'all') | ||||
self.assertFalse(im.visitdir('dir/foo')) | self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir('folder')) | self.assertFalse(im.visitdir(b'folder')) | ||||
# OPT: We should probably return 'all' for these; we don't because | # OPT: We should probably return 'all' for these; we don't because | ||||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just True. | # an 'all' pattern, just True. | ||||
self.assertEqual(im.visitdir('dir/subdir/z'), True) | self.assertEqual(im.visitdir(b'dir/subdir/z'), True) | ||||
self.assertEqual(im.visitdir('dir/subdir/x'), True) | self.assertEqual(im.visitdir(b'dir/subdir/x'), True) | ||||
def testVisitchildrensetM2SubdirPrefix(self): | def testVisitchildrensetM2SubdirPrefix(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
self.assertEqual(im.visitchildrenset('.'), {'dir'}) | self.assertEqual(im.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(im.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(im.visitchildrenset('dir/foo'), set()) | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset('folder'), set()) | self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
# OPT: We should probably return 'all' for these | # OPT: We should probably return 'all' for these | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/z'), 'this') | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'this') | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
# We're using includematcher instead of patterns because it behaves slightly | # We're using includematcher instead of patterns because it behaves slightly | ||||
# better (giving narrower results) than patternmatcher. | # better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeIncludfe(self): | def testVisitdirIncludeIncludfe(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['rootfilesin:dir']) | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
self.assertEqual(im.visitdir('.'), True) | self.assertEqual(im.visitdir(b'.'), True) | ||||
self.assertEqual(im.visitdir('dir'), True) | self.assertEqual(im.visitdir(b'dir'), True) | ||||
self.assertFalse(im.visitdir('dir/subdir')) | self.assertFalse(im.visitdir(b'dir/subdir')) | ||||
self.assertFalse(im.visitdir('dir/foo')) | self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir('folder')) | self.assertFalse(im.visitdir(b'folder')) | ||||
self.assertFalse(im.visitdir('dir/subdir/z')) | self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(im.visitdir('dir/subdir/x')) | self.assertFalse(im.visitdir(b'dir/subdir/x')) | ||||
def testVisitchildrensetIncludeInclude(self): | def testVisitchildrensetIncludeInclude(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['rootfilesin:dir']) | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
self.assertEqual(im.visitchildrenset('.'), {'dir'}) | self.assertEqual(im.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(im.visitchildrenset('dir'), 'this') | self.assertEqual(im.visitchildrenset(b'dir'), b'this') | ||||
self.assertEqual(im.visitchildrenset('dir/subdir'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/foo'), set()) | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset('folder'), set()) | self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/x'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | ||||
# We're using includematcher instead of patterns because it behaves slightly | # We're using includematcher instead of patterns because it behaves slightly | ||||
# better (giving narrower results) than patternmatcher. | # better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude2(self): | def testVisitdirIncludeInclude2(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['path:folder']) | m2 = matchmod.match(b'', b'', include=[b'path:folder']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
# FIXME: is True correct here? | # FIXME: is True correct here? | ||||
self.assertEqual(im.visitdir('.'), True) | self.assertEqual(im.visitdir(b'.'), True) | ||||
self.assertFalse(im.visitdir('dir')) | self.assertFalse(im.visitdir(b'dir')) | ||||
self.assertFalse(im.visitdir('dir/subdir')) | self.assertFalse(im.visitdir(b'dir/subdir')) | ||||
self.assertFalse(im.visitdir('dir/foo')) | self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir('folder')) | self.assertFalse(im.visitdir(b'folder')) | ||||
self.assertFalse(im.visitdir('dir/subdir/z')) | self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(im.visitdir('dir/subdir/x')) | self.assertFalse(im.visitdir(b'dir/subdir/x')) | ||||
def testVisitchildrensetIncludeInclude2(self): | def testVisitchildrensetIncludeInclude2(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['path:folder']) | m2 = matchmod.match(b'', b'', include=[b'path:folder']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
# FIXME: is set() correct here? | # FIXME: is set() correct here? | ||||
self.assertEqual(im.visitchildrenset('.'), set()) | self.assertEqual(im.visitchildrenset(b'.'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir'), set()) | self.assertEqual(im.visitchildrenset(b'dir'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/foo'), set()) | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset('folder'), set()) | self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/x'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | ||||
# We're using includematcher instead of patterns because it behaves slightly | # We're using includematcher instead of patterns because it behaves slightly | ||||
# better (giving narrower results) than patternmatcher. | # better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude3(self): | def testVisitdirIncludeInclude3(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
self.assertEqual(im.visitdir('.'), True) | self.assertEqual(im.visitdir(b'.'), True) | ||||
self.assertEqual(im.visitdir('dir'), True) | self.assertEqual(im.visitdir(b'dir'), True) | ||||
self.assertEqual(im.visitdir('dir/subdir'), True) | self.assertEqual(im.visitdir(b'dir/subdir'), True) | ||||
self.assertFalse(im.visitdir('dir/foo')) | self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir('folder')) | self.assertFalse(im.visitdir(b'folder')) | ||||
self.assertFalse(im.visitdir('dir/subdir/z')) | self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
# OPT: this should probably be 'all' not True. | # OPT: this should probably be 'all' not True. | ||||
self.assertEqual(im.visitdir('dir/subdir/x'), True) | self.assertEqual(im.visitdir(b'dir/subdir/x'), True) | ||||
def testVisitchildrensetIncludeInclude3(self): | def testVisitchildrensetIncludeInclude3(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
self.assertEqual(im.visitchildrenset('.'), {'dir'}) | self.assertEqual(im.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(im.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir'), {'x'}) | self.assertEqual(im.visitchildrenset(b'dir/subdir'), {b'x'}) | ||||
self.assertEqual(im.visitchildrenset('dir/foo'), set()) | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset('folder'), set()) | self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
# OPT: this should probably be 'all' not 'this'. | # OPT: this should probably be 'all' not 'this'. | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
# We're using includematcher instead of patterns because it behaves slightly | # We're using includematcher instead of patterns because it behaves slightly | ||||
# better (giving narrower results) than patternmatcher. | # better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude4(self): | def testVisitdirIncludeInclude4(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir/z']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
# OPT: these next three could probably be False as well. | # OPT: these next three could probably be False as well. | ||||
self.assertEqual(im.visitdir('.'), True) | self.assertEqual(im.visitdir(b'.'), True) | ||||
self.assertEqual(im.visitdir('dir'), True) | self.assertEqual(im.visitdir(b'dir'), True) | ||||
self.assertEqual(im.visitdir('dir/subdir'), True) | self.assertEqual(im.visitdir(b'dir/subdir'), True) | ||||
self.assertFalse(im.visitdir('dir/foo')) | self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir('folder')) | self.assertFalse(im.visitdir(b'folder')) | ||||
self.assertFalse(im.visitdir('dir/subdir/z')) | self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(im.visitdir('dir/subdir/x')) | self.assertFalse(im.visitdir(b'dir/subdir/x')) | ||||
def testVisitchildrensetIncludeInclude4(self): | def testVisitchildrensetIncludeInclude4(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir/z']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | ||||
im = matchmod.intersectmatchers(m1, m2) | im = matchmod.intersectmatchers(m1, m2) | ||||
# OPT: these next two could probably be set() as well. | # OPT: these next two could probably be set() as well. | ||||
self.assertEqual(im.visitchildrenset('.'), {'dir'}) | self.assertEqual(im.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(im.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/foo'), set()) | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset('folder'), set()) | self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(im.visitchildrenset('dir/subdir/x'), set()) | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | ||||
class UnionMatcherTests(unittest.TestCase): | class UnionMatcherTests(unittest.TestCase): | ||||
def testVisitdirM2always(self): | def testVisitdirM2always(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.alwaysmatcher('', '') | m2 = matchmod.alwaysmatcher(b'', b'') | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
# um should be equivalent to a alwaysmatcher. | # um should be equivalent to a alwaysmatcher. | ||||
self.assertEqual(um.visitdir('.'), 'all') | self.assertEqual(um.visitdir(b'.'), b'all') | ||||
self.assertEqual(um.visitdir('dir'), 'all') | self.assertEqual(um.visitdir(b'dir'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir/z'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir('dir/foo'), 'all') | self.assertEqual(um.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir/x'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitdir('folder'), 'all') | self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
def testVisitchildrensetM2always(self): | def testVisitchildrensetM2always(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.alwaysmatcher('', '') | m2 = matchmod.alwaysmatcher(b'', b'') | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
# um should be equivalent to a alwaysmatcher. | # um should be equivalent to a alwaysmatcher. | ||||
self.assertEqual(um.visitchildrenset('.'), 'all') | self.assertEqual(um.visitchildrenset(b'.'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/foo'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitchildrenset('folder'), 'all') | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
def testVisitdirM1never(self): | def testVisitdirM1never(self): | ||||
m1 = matchmod.nevermatcher('', '') | m1 = matchmod.nevermatcher(b'', b'') | ||||
m2 = matchmod.alwaysmatcher('', '') | m2 = matchmod.alwaysmatcher(b'', b'') | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
# um should be equivalent to a alwaysmatcher. | # um should be equivalent to a alwaysmatcher. | ||||
self.assertEqual(um.visitdir('.'), 'all') | self.assertEqual(um.visitdir(b'.'), b'all') | ||||
self.assertEqual(um.visitdir('dir'), 'all') | self.assertEqual(um.visitdir(b'dir'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir/z'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir('dir/foo'), 'all') | self.assertEqual(um.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir/x'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitdir('folder'), 'all') | self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
def testVisitchildrensetM1never(self): | def testVisitchildrensetM1never(self): | ||||
m1 = matchmod.nevermatcher('', '') | m1 = matchmod.nevermatcher(b'', b'') | ||||
m2 = matchmod.alwaysmatcher('', '') | m2 = matchmod.alwaysmatcher(b'', b'') | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
# um should be equivalent to a alwaysmatcher. | # um should be equivalent to a alwaysmatcher. | ||||
self.assertEqual(um.visitchildrenset('.'), 'all') | self.assertEqual(um.visitchildrenset(b'.'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/foo'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitchildrenset('folder'), 'all') | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
def testVisitdirM2never(self): | def testVisitdirM2never(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.nevermatcher('', '') | m2 = matchmod.nevermatcher(b'', b'') | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
# um should be equivalent to a alwaysmatcher. | # um should be equivalent to a alwaysmatcher. | ||||
self.assertEqual(um.visitdir('.'), 'all') | self.assertEqual(um.visitdir(b'.'), b'all') | ||||
self.assertEqual(um.visitdir('dir'), 'all') | self.assertEqual(um.visitdir(b'dir'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir/z'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir('dir/foo'), 'all') | self.assertEqual(um.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir/x'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitdir('folder'), 'all') | self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
def testVisitchildrensetM2never(self): | def testVisitchildrensetM2never(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.nevermatcher('', '') | m2 = matchmod.nevermatcher(b'', b'') | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
# um should be equivalent to a alwaysmatcher. | # um should be equivalent to a alwaysmatcher. | ||||
self.assertEqual(um.visitchildrenset('.'), 'all') | self.assertEqual(um.visitchildrenset(b'.'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/foo'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitchildrenset('folder'), 'all') | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
def testVisitdirM2SubdirPrefix(self): | def testVisitdirM2SubdirPrefix(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.match('', '', patterns=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
self.assertEqual(um.visitdir('.'), 'all') | self.assertEqual(um.visitdir(b'.'), b'all') | ||||
self.assertEqual(um.visitdir('dir'), 'all') | self.assertEqual(um.visitdir(b'dir'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitdir('dir/foo'), 'all') | self.assertEqual(um.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitdir('folder'), 'all') | self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir/z'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir/x'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
def testVisitchildrensetM2SubdirPrefix(self): | def testVisitchildrensetM2SubdirPrefix(self): | ||||
m1 = matchmod.alwaysmatcher('', '') | m1 = matchmod.alwaysmatcher(b'', b'') | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
self.assertEqual(um.visitchildrenset('.'), 'all') | self.assertEqual(um.visitchildrenset(b'.'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/foo'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitchildrenset('folder'), 'all') | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
# We're using includematcher instead of patterns because it behaves slightly | # We're using includematcher instead of patterns because it behaves slightly | ||||
# better (giving narrower results) than patternmatcher. | # better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeIncludfe(self): | def testVisitdirIncludeIncludfe(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['rootfilesin:dir']) | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
self.assertEqual(um.visitdir('.'), True) | self.assertEqual(um.visitdir(b'.'), True) | ||||
self.assertEqual(um.visitdir('dir'), True) | self.assertEqual(um.visitdir(b'dir'), True) | ||||
self.assertEqual(um.visitdir('dir/subdir'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertFalse(um.visitdir('dir/foo')) | self.assertFalse(um.visitdir(b'dir/foo')) | ||||
self.assertFalse(um.visitdir('folder')) | self.assertFalse(um.visitdir(b'folder')) | ||||
# OPT: These two should probably be 'all' not True. | # OPT: These two should probably be 'all' not True. | ||||
self.assertEqual(um.visitdir('dir/subdir/z'), True) | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) | ||||
self.assertEqual(um.visitdir('dir/subdir/x'), True) | self.assertEqual(um.visitdir(b'dir/subdir/x'), True) | ||||
def testVisitchildrensetIncludeInclude(self): | def testVisitchildrensetIncludeInclude(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['rootfilesin:dir']) | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
self.assertEqual(um.visitchildrenset('.'), {'dir'}) | self.assertEqual(um.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(um.visitchildrenset('dir'), 'this') | self.assertEqual(um.visitchildrenset(b'dir'), b'this') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/foo'), set()) | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(um.visitchildrenset('folder'), set()) | self.assertEqual(um.visitchildrenset(b'folder'), set()) | ||||
# OPT: These next two could be 'all' instead of 'this'. | # OPT: These next two could be 'all' instead of 'this'. | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'this') | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
# We're using includematcher instead of patterns because it behaves slightly | # We're using includematcher instead of patterns because it behaves slightly | ||||
# better (giving narrower results) than patternmatcher. | # better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude2(self): | def testVisitdirIncludeInclude2(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['path:folder']) | m2 = matchmod.match(b'', b'', include=[b'path:folder']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
self.assertEqual(um.visitdir('.'), True) | self.assertEqual(um.visitdir(b'.'), True) | ||||
self.assertEqual(um.visitdir('dir'), True) | self.assertEqual(um.visitdir(b'dir'), True) | ||||
self.assertEqual(um.visitdir('dir/subdir'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertFalse(um.visitdir('dir/foo')) | self.assertFalse(um.visitdir(b'dir/foo')) | ||||
self.assertEqual(um.visitdir('folder'), 'all') | self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
# OPT: These should probably be 'all' not True. | # OPT: These should probably be 'all' not True. | ||||
self.assertEqual(um.visitdir('dir/subdir/z'), True) | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) | ||||
self.assertEqual(um.visitdir('dir/subdir/x'), True) | self.assertEqual(um.visitdir(b'dir/subdir/x'), True) | ||||
def testVisitchildrensetIncludeInclude2(self): | def testVisitchildrensetIncludeInclude2(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
m2 = matchmod.match('', '', include=['path:folder']) | m2 = matchmod.match(b'', b'', include=[b'path:folder']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
self.assertEqual(um.visitchildrenset('.'), {'folder', 'dir'}) | self.assertEqual(um.visitchildrenset(b'.'), {b'folder', b'dir'}) | ||||
self.assertEqual(um.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/foo'), set()) | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(um.visitchildrenset('folder'), 'all') | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
# OPT: These next two could be 'all' instead of 'this'. | # OPT: These next two could be 'all' instead of 'this'. | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'this') | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'this') | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
# We're using includematcher instead of patterns because it behaves slightly | # We're using includematcher instead of patterns because it behaves slightly | ||||
# better (giving narrower results) than patternmatcher. | # better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude3(self): | def testVisitdirIncludeInclude3(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
self.assertEqual(um.visitdir('.'), True) | self.assertEqual(um.visitdir(b'.'), True) | ||||
self.assertEqual(um.visitdir('dir'), True) | self.assertEqual(um.visitdir(b'dir'), True) | ||||
self.assertEqual(um.visitdir('dir/subdir'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertFalse(um.visitdir('dir/foo')) | self.assertFalse(um.visitdir(b'dir/foo')) | ||||
self.assertFalse(um.visitdir('folder')) | self.assertFalse(um.visitdir(b'folder')) | ||||
self.assertEqual(um.visitdir('dir/subdir/x'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
# OPT: this should probably be 'all' not True. | # OPT: this should probably be 'all' not True. | ||||
self.assertEqual(um.visitdir('dir/subdir/z'), True) | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) | ||||
def testVisitchildrensetIncludeInclude3(self): | def testVisitchildrensetIncludeInclude3(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
self.assertEqual(um.visitchildrenset('.'), {'dir'}) | self.assertEqual(um.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(um.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/foo'), set()) | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(um.visitchildrenset('folder'), set()) | self.assertEqual(um.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
# OPT: this should probably be 'all' not 'this'. | # OPT: this should probably be 'all' not 'this'. | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'this') | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') | ||||
# We're using includematcher instead of patterns because it behaves slightly | # We're using includematcher instead of patterns because it behaves slightly | ||||
# better (giving narrower results) than patternmatcher. | # better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude4(self): | def testVisitdirIncludeInclude4(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir/z']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
# OPT: these next three could probably be False as well. | # OPT: these next three could probably be False as well. | ||||
self.assertEqual(um.visitdir('.'), True) | self.assertEqual(um.visitdir(b'.'), True) | ||||
self.assertEqual(um.visitdir('dir'), True) | self.assertEqual(um.visitdir(b'dir'), True) | ||||
self.assertEqual(um.visitdir('dir/subdir'), True) | self.assertEqual(um.visitdir(b'dir/subdir'), True) | ||||
self.assertFalse(um.visitdir('dir/foo')) | self.assertFalse(um.visitdir(b'dir/foo')) | ||||
self.assertFalse(um.visitdir('folder')) | self.assertFalse(um.visitdir(b'folder')) | ||||
self.assertEqual(um.visitdir('dir/subdir/z'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir('dir/subdir/x'), 'all') | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
def testVisitchildrensetIncludeInclude4(self): | def testVisitchildrensetIncludeInclude4(self): | ||||
m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||||
m2 = matchmod.match('', '', include=['path:dir/subdir/z']) | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | ||||
um = matchmod.unionmatcher([m1, m2]) | um = matchmod.unionmatcher([m1, m2]) | ||||
self.assertEqual(um.visitchildrenset('.'), {'dir'}) | self.assertEqual(um.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(um.visitchildrenset('dir'), {'subdir'}) | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(um.visitchildrenset('dir/subdir'), {'x', 'z'}) | self.assertEqual(um.visitchildrenset(b'dir/subdir'), {b'x', b'z'}) | ||||
self.assertEqual(um.visitchildrenset('dir/foo'), set()) | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(um.visitchildrenset('folder'), set()) | self.assertEqual(um.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
class SubdirMatcherTests(unittest.TestCase): | class SubdirMatcherTests(unittest.TestCase): | ||||
def testVisitdir(self): | def testVisitdir(self): | ||||
m = matchmod.match('', '', include=['path:dir/subdir']) | m = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
sm = matchmod.subdirmatcher('dir', m) | sm = matchmod.subdirmatcher(b'dir', m) | ||||
self.assertEqual(sm.visitdir('.'), True) | self.assertEqual(sm.visitdir(b'.'), True) | ||||
self.assertEqual(sm.visitdir('subdir'), 'all') | self.assertEqual(sm.visitdir(b'subdir'), b'all') | ||||
# OPT: These next two should probably be 'all' not True. | # OPT: These next two should probably be 'all' not True. | ||||
self.assertEqual(sm.visitdir('subdir/x'), True) | self.assertEqual(sm.visitdir(b'subdir/x'), True) | ||||
self.assertEqual(sm.visitdir('subdir/z'), True) | self.assertEqual(sm.visitdir(b'subdir/z'), True) | ||||
self.assertFalse(sm.visitdir('foo')) | self.assertFalse(sm.visitdir(b'foo')) | ||||
def testVisitchildrenset(self): | def testVisitchildrenset(self): | ||||
m = matchmod.match('', '', include=['path:dir/subdir']) | m = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
sm = matchmod.subdirmatcher('dir', m) | sm = matchmod.subdirmatcher(b'dir', m) | ||||
self.assertEqual(sm.visitchildrenset('.'), {'subdir'}) | self.assertEqual(sm.visitchildrenset(b'.'), {b'subdir'}) | ||||
self.assertEqual(sm.visitchildrenset('subdir'), 'all') | self.assertEqual(sm.visitchildrenset(b'subdir'), b'all') | ||||
# OPT: These next two should probably be 'all' not 'this'. | # OPT: These next two should probably be 'all' not 'this'. | ||||
self.assertEqual(sm.visitchildrenset('subdir/x'), 'this') | self.assertEqual(sm.visitchildrenset(b'subdir/x'), b'this') | ||||
self.assertEqual(sm.visitchildrenset('subdir/z'), 'this') | self.assertEqual(sm.visitchildrenset(b'subdir/z'), b'this') | ||||
self.assertEqual(sm.visitchildrenset('foo'), set()) | self.assertEqual(sm.visitchildrenset(b'foo'), set()) | ||||
class PrefixdirMatcherTests(unittest.TestCase): | class PrefixdirMatcherTests(unittest.TestCase): | ||||
def testVisitdir(self): | def testVisitdir(self): | ||||
m = matchmod.match(util.localpath('root/d'), 'e/f', | m = matchmod.match(util.localpath(b'root/d'), b'e/f', | ||||
['../a.txt', 'b.txt']) | [b'../a.txt', b'b.txt']) | ||||
pm = matchmod.prefixdirmatcher('root', 'd/e/f', 'd', m) | pm = matchmod.prefixdirmatcher(b'root', b'd/e/f', b'd', m) | ||||
# `m` elides 'd' because it's part of the root, and the rest of the | # `m` elides 'd' because it's part of the root, and the rest of the | ||||
# patterns are relative. | # patterns are relative. | ||||
self.assertEqual(bool(m('a.txt')), False) | self.assertEqual(bool(m(b'a.txt')), False) | ||||
self.assertEqual(bool(m('b.txt')), False) | self.assertEqual(bool(m(b'b.txt')), False) | ||||
self.assertEqual(bool(m('e/a.txt')), True) | self.assertEqual(bool(m(b'e/a.txt')), True) | ||||
self.assertEqual(bool(m('e/b.txt')), False) | self.assertEqual(bool(m(b'e/b.txt')), False) | ||||
self.assertEqual(bool(m('e/f/b.txt')), True) | self.assertEqual(bool(m(b'e/f/b.txt')), True) | ||||
# The prefix matcher re-adds 'd' to the paths, so they need to be | # The prefix matcher re-adds 'd' to the paths, so they need to be | ||||
# specified when using the prefixdirmatcher. | # specified when using the prefixdirmatcher. | ||||
self.assertEqual(bool(pm('a.txt')), False) | self.assertEqual(bool(pm(b'a.txt')), False) | ||||
self.assertEqual(bool(pm('b.txt')), False) | self.assertEqual(bool(pm(b'b.txt')), False) | ||||
self.assertEqual(bool(pm('d/e/a.txt')), True) | self.assertEqual(bool(pm(b'd/e/a.txt')), True) | ||||
self.assertEqual(bool(pm('d/e/b.txt')), False) | self.assertEqual(bool(pm(b'd/e/b.txt')), False) | ||||
self.assertEqual(bool(pm('d/e/f/b.txt')), True) | self.assertEqual(bool(pm(b'd/e/f/b.txt')), True) | ||||
self.assertEqual(m.visitdir('.'), True) | self.assertEqual(m.visitdir(b'.'), True) | ||||
self.assertEqual(m.visitdir('e'), True) | self.assertEqual(m.visitdir(b'e'), True) | ||||
self.assertEqual(m.visitdir('e/f'), True) | self.assertEqual(m.visitdir(b'e/f'), True) | ||||
self.assertEqual(m.visitdir('e/f/g'), False) | self.assertEqual(m.visitdir(b'e/f/g'), False) | ||||
self.assertEqual(pm.visitdir('.'), True) | self.assertEqual(pm.visitdir(b'.'), True) | ||||
self.assertEqual(pm.visitdir('d'), True) | self.assertEqual(pm.visitdir(b'd'), True) | ||||
self.assertEqual(pm.visitdir('d/e'), True) | self.assertEqual(pm.visitdir(b'd/e'), True) | ||||
self.assertEqual(pm.visitdir('d/e/f'), True) | self.assertEqual(pm.visitdir(b'd/e/f'), True) | ||||
self.assertEqual(pm.visitdir('d/e/f/g'), False) | self.assertEqual(pm.visitdir(b'd/e/f/g'), False) | ||||
def testVisitchildrenset(self): | def testVisitchildrenset(self): | ||||
m = matchmod.match(util.localpath('root/d'), 'e/f', | m = matchmod.match(util.localpath(b'root/d'), b'e/f', | ||||
['../a.txt', 'b.txt']) | [b'../a.txt', b'b.txt']) | ||||
pm = matchmod.prefixdirmatcher('root', 'd/e/f', 'd', m) | pm = matchmod.prefixdirmatcher(b'root', b'd/e/f', b'd', m) | ||||
# OPT: visitchildrenset could possibly return {'e'} and {'f'} for these | # OPT: visitchildrenset could possibly return {'e'} and {'f'} for these | ||||
# next two, respectively; patternmatcher does not have this | # next two, respectively; patternmatcher does not have this | ||||
# optimization. | # optimization. | ||||
self.assertEqual(m.visitchildrenset('.'), 'this') | self.assertEqual(m.visitchildrenset(b'.'), b'this') | ||||
self.assertEqual(m.visitchildrenset('e'), 'this') | self.assertEqual(m.visitchildrenset(b'e'), b'this') | ||||
self.assertEqual(m.visitchildrenset('e/f'), 'this') | self.assertEqual(m.visitchildrenset(b'e/f'), b'this') | ||||
self.assertEqual(m.visitchildrenset('e/f/g'), set()) | self.assertEqual(m.visitchildrenset(b'e/f/g'), set()) | ||||
# OPT: visitchildrenset could possibly return {'d'}, {'e'}, and {'f'} | # OPT: visitchildrenset could possibly return {'d'}, {'e'}, and {'f'} | ||||
# for these next three, respectively; patternmatcher does not have this | # for these next three, respectively; patternmatcher does not have this | ||||
# optimization. | # optimization. | ||||
self.assertEqual(pm.visitchildrenset('.'), 'this') | self.assertEqual(pm.visitchildrenset(b'.'), b'this') | ||||
self.assertEqual(pm.visitchildrenset('d'), 'this') | self.assertEqual(pm.visitchildrenset(b'd'), b'this') | ||||
self.assertEqual(pm.visitchildrenset('d/e'), 'this') | self.assertEqual(pm.visitchildrenset(b'd/e'), b'this') | ||||
self.assertEqual(pm.visitchildrenset('d/e/f'), 'this') | self.assertEqual(pm.visitchildrenset(b'd/e/f'), b'this') | ||||
self.assertEqual(pm.visitchildrenset('d/e/f/g'), set()) | self.assertEqual(pm.visitchildrenset(b'd/e/f/g'), set()) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
silenttestrunner.main(__name__) | silenttestrunner.main(__name__) |