dagop: minor python optimization to `headrevs`
Less lookup and less function call never hurt. This provides a small speedup
on various run of the 'heads()' revset. This also buys back some of the slow
down we observed in the previous changesets for single value lookup.
Performance number:
0) before dagop.headrevs usage
1) after dagop.headrevs usage
2) after this change
revset: heads(all())
plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast
0) 0.036503 0.032564 0.030024 0.032378 0.030887 0.036367 0.031713 0.032205 0.036467 0.032286 0.030300
1) 0.036668 0.035347 108% 0.035611 118% 0.035358 109% 0.035726 115% 0.036411 0.035261 111% 0.036096 112% 0.036052 0.035095 108% 0.035792 118%
2) 0.034254 93% 0.034482 0.035003 0.034353 0.033754 94% 0.034689 0.034361 0.035059 0.034636 0.034662 0.035465
revset: heads(-10000:-1)
plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast
0) 0.003936 0.003218 0.003227 0.003302 0.003328 0.003848 0.003305 0.003252 0.003839 0.003306 0.003279
1) 0.003870 0.003785 117% 0.003821 118% 0.003780 114% 0.003769 113% 0.003776 0.003792 114% 0.003805 117% 0.003810 0.003798 114% 0.003840 117%
2) 0.003666 94% 0.003577 94% 0.003632 0.003644 0.003614 0.003638 0.003652 0.003632 0.003661 0.003660 0.003658
revset: (-5000:-1000) and heads(-10000:-1)
plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast
0) 0.004244 0.003368 0.003313 0.003367 0.003327 0.004325 0.003401 0.003379 0.004310 0.003359 0.003396
1) 0.003969 93% 0.003862 114% 0.003834 115% 0.003810 113% 0.003822 114% 0.003940 91% 0.003908 114% 0.003814 112% 0.003986 92% 0.003954 117% 0.003816 112%
2) 0.003728 93% 0.003638 94% 0.003659 0.003685 0.003628 94% 0.003716 94% 0.003653 93% 0.003655 0.003748 94% 0.003740 94% 0.003686
revset: heads(matching(tip, "author"))
plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast
0) 7.574666 7.545950 7.570743 7.578697 7.525725 7.509929 7.443854 7.488442 7.452880 7.445411 7.689107
1) 7.549390 7.389162 7.529790 7.536297 7.450467 7.555347 7.404586 7.514948 7.542794 7.524787 7.536918
2) 7.568294 7.479326 7.578624 7.380375 7.440102 7.454218 7.515189 7.556511 7.524585 7.537566 7.507418
revset: heads(matching(tip, "author")) and -10000:-1
plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast
0) 7.512533 7.605877 7.382894 7.462109 7.420086 7.575034 7.448452 7.549374 7.457880 7.450308 7.515019
1) 7.548677 7.551832 7.629598 7.494857 7.550554 7.521838 7.451794 error 7.321781 7.546885 7.557523
2) 7.451985 7.541044 7.506563 7.470928 7.512618 7.474988 7.498887 7.547930 7.560276 7.618599 7.465442
revset: (-10000:-1) and heads(matching(tip, "author"))
plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast
0) 7.465419 7.570089 7.439594 7.521221 7.498716 7.492922 7.479108 7.552397 7.407888 error 7.468264
1) 7.539866 7.548045 7.491761 7.517170 7.469824 7.501990 7.579102 7.502568 7.578102 7.555754 7.567622
2) 7.370463 7.514712 7.497024 7.679428 7.638138 7.490775 7.472273 7.652587 7.584139 7.511893 7.466384
from __future__ import absolute_import
import unittest
import silenttestrunner
from mercurial import (
match as matchmod,
util,
)
class BaseMatcherTests(unittest.TestCase):
def testVisitdir(self):
m = matchmod.basematcher(b'', b'')
self.assertTrue(m.visitdir(b'.'))
self.assertTrue(m.visitdir(b'dir'))
def testVisitchildrenset(self):
m = matchmod.basematcher(b'', b'')
self.assertEqual(m.visitchildrenset(b'.'), b'this')
self.assertEqual(m.visitchildrenset(b'dir'), b'this')
class AlwaysMatcherTests(unittest.TestCase):
def testVisitdir(self):
m = matchmod.alwaysmatcher(b'', b'')
self.assertEqual(m.visitdir(b'.'), b'all')
self.assertEqual(m.visitdir(b'dir'), b'all')
def testVisitchildrenset(self):
m = matchmod.alwaysmatcher(b'', b'')
self.assertEqual(m.visitchildrenset(b'.'), b'all')
self.assertEqual(m.visitchildrenset(b'dir'), b'all')
class NeverMatcherTests(unittest.TestCase):
def testVisitdir(self):
m = matchmod.nevermatcher(b'', b'')
self.assertFalse(m.visitdir(b'.'))
self.assertFalse(m.visitdir(b'dir'))
def testVisitchildrenset(self):
m = matchmod.nevermatcher(b'', b'')
self.assertEqual(m.visitchildrenset(b'.'), set())
self.assertEqual(m.visitchildrenset(b'dir'), set())
class PredicateMatcherTests(unittest.TestCase):
# predicatematcher does not currently define either of these methods, so
# this is equivalent to BaseMatcherTests.
def testVisitdir(self):
m = matchmod.predicatematcher(b'', b'', lambda *a: False)
self.assertTrue(m.visitdir(b'.'))
self.assertTrue(m.visitdir(b'dir'))
def testVisitchildrenset(self):
m = matchmod.predicatematcher(b'', b'', lambda *a: False)
self.assertEqual(m.visitchildrenset(b'.'), b'this')
self.assertEqual(m.visitchildrenset(b'dir'), b'this')
class PatternMatcherTests(unittest.TestCase):
def testVisitdirPrefix(self):
m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir'])
assert isinstance(m, matchmod.patternmatcher)
self.assertTrue(m.visitdir(b'.'))
self.assertTrue(m.visitdir(b'dir'))
self.assertEqual(m.visitdir(b'dir/subdir'), b'all')
# OPT: This should probably be 'all' if its parent is?
self.assertTrue(m.visitdir(b'dir/subdir/x'))
self.assertFalse(m.visitdir(b'folder'))
def testVisitchildrensetPrefix(self):
m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir'])
assert isinstance(m, matchmod.patternmatcher)
self.assertEqual(m.visitchildrenset(b'.'), b'this')
self.assertEqual(m.visitchildrenset(b'dir'), b'this')
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all')
# OPT: This should probably be 'all' if its parent is?
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this')
self.assertEqual(m.visitchildrenset(b'folder'), set())
def testVisitdirRootfilesin(self):
m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir'])
assert isinstance(m, matchmod.patternmatcher)
self.assertTrue(m.visitdir(b'.'))
self.assertFalse(m.visitdir(b'dir/subdir/x'))
self.assertFalse(m.visitdir(b'folder'))
# FIXME: These should probably be True.
self.assertFalse(m.visitdir(b'dir'))
self.assertFalse(m.visitdir(b'dir/subdir'))
def testVisitchildrensetRootfilesin(self):
m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir'])
assert isinstance(m, matchmod.patternmatcher)
self.assertEqual(m.visitchildrenset(b'.'), b'this')
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set())
self.assertEqual(m.visitchildrenset(b'folder'), set())
# FIXME: These should probably be {'subdir'} and 'this', respectively,
# or at least 'this' and 'this'.
self.assertEqual(m.visitchildrenset(b'dir'), set())
self.assertEqual(m.visitchildrenset(b'dir/subdir'), set())
def testVisitdirGlob(self):
m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*'])
assert isinstance(m, matchmod.patternmatcher)
self.assertTrue(m.visitdir(b'.'))
self.assertTrue(m.visitdir(b'dir'))
self.assertFalse(m.visitdir(b'folder'))
# OPT: these should probably be False.
self.assertTrue(m.visitdir(b'dir/subdir'))
self.assertTrue(m.visitdir(b'dir/subdir/x'))
def testVisitchildrensetGlob(self):
m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*'])
assert isinstance(m, matchmod.patternmatcher)
self.assertEqual(m.visitchildrenset(b'.'), b'this')
self.assertEqual(m.visitchildrenset(b'folder'), set())
self.assertEqual(m.visitchildrenset(b'dir'), b'this')
# OPT: these should probably be set().
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this')
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this')
class IncludeMatcherTests(unittest.TestCase):
def testVisitdirPrefix(self):
m = matchmod.match(b'x', b'', include=[b'path:dir/subdir'])
assert isinstance(m, matchmod.includematcher)
self.assertTrue(m.visitdir(b'.'))
self.assertTrue(m.visitdir(b'dir'))
self.assertEqual(m.visitdir(b'dir/subdir'), b'all')
# OPT: This should probably be 'all' if its parent is?
self.assertTrue(m.visitdir(b'dir/subdir/x'))
self.assertFalse(m.visitdir(b'folder'))
def testVisitchildrensetPrefix(self):
m = matchmod.match(b'x', b'', include=[b'path:dir/subdir'])
assert isinstance(m, matchmod.includematcher)
self.assertEqual(m.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all')
# OPT: This should probably be 'all' if its parent is?
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this')
self.assertEqual(m.visitchildrenset(b'folder'), set())
def testVisitdirRootfilesin(self):
m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir'])
assert isinstance(m, matchmod.includematcher)
self.assertTrue(m.visitdir(b'.'))
self.assertTrue(m.visitdir(b'dir'))
self.assertTrue(m.visitdir(b'dir/subdir'))
self.assertFalse(m.visitdir(b'dir/subdir/x'))
self.assertFalse(m.visitdir(b'folder'))
def testVisitchildrensetRootfilesin(self):
m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir'])
assert isinstance(m, matchmod.includematcher)
self.assertEqual(m.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this')
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set())
self.assertEqual(m.visitchildrenset(b'folder'), set())
def testVisitdirGlob(self):
m = matchmod.match(b'x', b'', include=[b'glob:dir/z*'])
assert isinstance(m, matchmod.includematcher)
self.assertTrue(m.visitdir(b'.'))
self.assertTrue(m.visitdir(b'dir'))
self.assertFalse(m.visitdir(b'folder'))
# OPT: these should probably be False.
self.assertTrue(m.visitdir(b'dir/subdir'))
self.assertTrue(m.visitdir(b'dir/subdir/x'))
def testVisitchildrensetGlob(self):
m = matchmod.match(b'x', b'', include=[b'glob:dir/z*'])
assert isinstance(m, matchmod.includematcher)
self.assertEqual(m.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(m.visitchildrenset(b'folder'), set())
self.assertEqual(m.visitchildrenset(b'dir'), b'this')
# OPT: these should probably be set().
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this')
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this')
class ExactMatcherTests(unittest.TestCase):
def testVisitdir(self):
m = matchmod.match(b'x', b'', patterns=[b'dir/subdir/foo.txt'],
exact=True)
assert isinstance(m, matchmod.exactmatcher)
self.assertTrue(m.visitdir(b'.'))
self.assertTrue(m.visitdir(b'dir'))
self.assertTrue(m.visitdir(b'dir/subdir'))
self.assertFalse(m.visitdir(b'dir/subdir/foo.txt'))
self.assertFalse(m.visitdir(b'dir/foo'))
self.assertFalse(m.visitdir(b'dir/subdir/x'))
self.assertFalse(m.visitdir(b'folder'))
def testVisitchildrenset(self):
m = matchmod.match(b'x', b'', patterns=[b'dir/subdir/foo.txt'],
exact=True)
assert isinstance(m, matchmod.exactmatcher)
self.assertEqual(m.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(m.visitchildrenset(b'dir/subdir'), {b'foo.txt'})
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set())
self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set())
self.assertEqual(m.visitchildrenset(b'folder'), set())
def testVisitchildrensetFilesAndDirs(self):
m = matchmod.match(b'x', b'', patterns=[b'rootfile.txt',
b'a/file1.txt',
b'a/b/file2.txt',
# no file in a/b/c
b'a/b/c/d/file4.txt'],
exact=True)
assert isinstance(m, matchmod.exactmatcher)
self.assertEqual(m.visitchildrenset(b'.'), {b'a', b'rootfile.txt'})
self.assertEqual(m.visitchildrenset(b'a'), {b'b', b'file1.txt'})
self.assertEqual(m.visitchildrenset(b'a/b'), {b'c', b'file2.txt'})
self.assertEqual(m.visitchildrenset(b'a/b/c'), {b'd'})
self.assertEqual(m.visitchildrenset(b'a/b/c/d'), {b'file4.txt'})
self.assertEqual(m.visitchildrenset(b'a/b/c/d/e'), set())
self.assertEqual(m.visitchildrenset(b'folder'), set())
class DifferenceMatcherTests(unittest.TestCase):
def testVisitdirM2always(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.alwaysmatcher(b'', b'')
dm = matchmod.differencematcher(m1, m2)
# dm should be equivalent to a nevermatcher.
self.assertFalse(dm.visitdir(b'.'))
self.assertFalse(dm.visitdir(b'dir'))
self.assertFalse(dm.visitdir(b'dir/subdir'))
self.assertFalse(dm.visitdir(b'dir/subdir/z'))
self.assertFalse(dm.visitdir(b'dir/foo'))
self.assertFalse(dm.visitdir(b'dir/subdir/x'))
self.assertFalse(dm.visitdir(b'folder'))
def testVisitchildrensetM2always(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.alwaysmatcher(b'', b'')
dm = matchmod.differencematcher(m1, m2)
# dm should be equivalent to a nevermatcher.
self.assertEqual(dm.visitchildrenset(b'.'), set())
self.assertEqual(dm.visitchildrenset(b'dir'), set())
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set())
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), set())
self.assertEqual(dm.visitchildrenset(b'dir/foo'), set())
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), set())
self.assertEqual(dm.visitchildrenset(b'folder'), set())
def testVisitdirM2never(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.nevermatcher(b'', b'')
dm = matchmod.differencematcher(m1, m2)
# dm should be equivalent to a alwaysmatcher. OPT: if m2 is a
# nevermatcher, we could return 'all' for these.
#
# 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.
# While we may want to eventually make these return 'all', they should
# not currently do so.
self.assertEqual(dm.visitdir(b'.'), True)
self.assertEqual(dm.visitdir(b'dir'), True)
self.assertEqual(dm.visitdir(b'dir/subdir'), True)
self.assertEqual(dm.visitdir(b'dir/subdir/z'), True)
self.assertEqual(dm.visitdir(b'dir/foo'), True)
self.assertEqual(dm.visitdir(b'dir/subdir/x'), True)
self.assertEqual(dm.visitdir(b'folder'), True)
def testVisitchildrensetM2never(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.nevermatcher(b'', b'')
dm = matchmod.differencematcher(m1, m2)
# dm should be equivalent to a alwaysmatcher.
self.assertEqual(dm.visitchildrenset(b'.'), b'all')
self.assertEqual(dm.visitchildrenset(b'dir'), b'all')
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'all')
self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all')
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'all')
self.assertEqual(dm.visitchildrenset(b'folder'), b'all')
def testVisitdirM2SubdirPrefix(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir'])
dm = matchmod.differencematcher(m1, m2)
self.assertEqual(dm.visitdir(b'.'), True)
self.assertEqual(dm.visitdir(b'dir'), True)
self.assertFalse(dm.visitdir(b'dir/subdir'))
# OPT: We should probably return False for these; we don't because
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of
# an 'all' pattern, just True.
self.assertEqual(dm.visitdir(b'dir/subdir/z'), True)
self.assertEqual(dm.visitdir(b'dir/subdir/x'), True)
# OPT: We could return 'all' for these.
self.assertEqual(dm.visitdir(b'dir/foo'), True)
self.assertEqual(dm.visitdir(b'folder'), True)
def testVisitchildrensetM2SubdirPrefix(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir'])
dm = matchmod.differencematcher(m1, m2)
self.assertEqual(dm.visitchildrenset(b'.'), b'this')
self.assertEqual(dm.visitchildrenset(b'dir'), b'this')
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set())
self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all')
self.assertEqual(dm.visitchildrenset(b'folder'), b'all')
# OPT: We should probably return set() for these; we don't because
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of
# an 'all' pattern, just 'this'.
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this')
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this')
# We're using includematcher instead of patterns because it behaves slightly
# better (giving narrower results) than patternmatcher.
def testVisitdirIncludeIncludfe(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir'])
dm = matchmod.differencematcher(m1, m2)
self.assertEqual(dm.visitdir(b'.'), True)
self.assertEqual(dm.visitdir(b'dir'), True)
self.assertEqual(dm.visitdir(b'dir/subdir'), True)
self.assertFalse(dm.visitdir(b'dir/foo'))
self.assertFalse(dm.visitdir(b'folder'))
# OPT: We should probably return False for these; we don't because
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of
# an 'all' pattern, just True.
self.assertEqual(dm.visitdir(b'dir/subdir/z'), True)
self.assertEqual(dm.visitdir(b'dir/subdir/x'), True)
def testVisitchildrensetIncludeInclude(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir'])
dm = matchmod.differencematcher(m1, m2)
self.assertEqual(dm.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(dm.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(dm.visitchildrenset(b'dir/foo'), set())
self.assertEqual(dm.visitchildrenset(b'folder'), set())
# OPT: We should probably return set() for these; we don't because
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of
# an 'all' pattern, just 'this'.
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this')
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this')
class IntersectionMatcherTests(unittest.TestCase):
def testVisitdirM2always(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.alwaysmatcher(b'', b'')
im = matchmod.intersectmatchers(m1, m2)
# im should be equivalent to a alwaysmatcher.
self.assertEqual(im.visitdir(b'.'), b'all')
self.assertEqual(im.visitdir(b'dir'), b'all')
self.assertEqual(im.visitdir(b'dir/subdir'), b'all')
self.assertEqual(im.visitdir(b'dir/subdir/z'), b'all')
self.assertEqual(im.visitdir(b'dir/foo'), b'all')
self.assertEqual(im.visitdir(b'dir/subdir/x'), b'all')
self.assertEqual(im.visitdir(b'folder'), b'all')
def testVisitchildrensetM2always(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.alwaysmatcher(b'', b'')
im = matchmod.intersectmatchers(m1, m2)
# im should be equivalent to a alwaysmatcher.
self.assertEqual(im.visitchildrenset(b'.'), b'all')
self.assertEqual(im.visitchildrenset(b'dir'), b'all')
self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'all')
self.assertEqual(im.visitchildrenset(b'dir/foo'), b'all')
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'all')
self.assertEqual(im.visitchildrenset(b'folder'), b'all')
def testVisitdirM2never(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.nevermatcher(b'', b'')
im = matchmod.intersectmatchers(m1, m2)
# im should be equivalent to a nevermatcher.
self.assertFalse(im.visitdir(b'.'))
self.assertFalse(im.visitdir(b'dir'))
self.assertFalse(im.visitdir(b'dir/subdir'))
self.assertFalse(im.visitdir(b'dir/subdir/z'))
self.assertFalse(im.visitdir(b'dir/foo'))
self.assertFalse(im.visitdir(b'dir/subdir/x'))
self.assertFalse(im.visitdir(b'folder'))
def testVisitchildrensetM2never(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.nevermatcher(b'', b'')
im = matchmod.intersectmatchers(m1, m2)
# im should be equivalent to a nevermqtcher.
self.assertEqual(im.visitchildrenset(b'.'), set())
self.assertEqual(im.visitchildrenset(b'dir'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set())
self.assertEqual(im.visitchildrenset(b'dir/foo'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set())
self.assertEqual(im.visitchildrenset(b'folder'), set())
def testVisitdirM2SubdirPrefix(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir'])
im = matchmod.intersectmatchers(m1, m2)
self.assertEqual(im.visitdir(b'.'), True)
self.assertEqual(im.visitdir(b'dir'), True)
self.assertEqual(im.visitdir(b'dir/subdir'), b'all')
self.assertFalse(im.visitdir(b'dir/foo'))
self.assertFalse(im.visitdir(b'folder'))
# OPT: We should probably return 'all' for these; we don't because
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of
# an 'all' pattern, just True.
self.assertEqual(im.visitdir(b'dir/subdir/z'), True)
self.assertEqual(im.visitdir(b'dir/subdir/x'), True)
def testVisitchildrensetM2SubdirPrefix(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
im = matchmod.intersectmatchers(m1, m2)
self.assertEqual(im.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(im.visitchildrenset(b'dir/foo'), set())
self.assertEqual(im.visitchildrenset(b'folder'), set())
# OPT: We should probably return 'all' for these
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'this')
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this')
# We're using includematcher instead of patterns because it behaves slightly
# better (giving narrower results) than patternmatcher.
def testVisitdirIncludeIncludfe(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir'])
im = matchmod.intersectmatchers(m1, m2)
self.assertEqual(im.visitdir(b'.'), True)
self.assertEqual(im.visitdir(b'dir'), True)
self.assertFalse(im.visitdir(b'dir/subdir'))
self.assertFalse(im.visitdir(b'dir/foo'))
self.assertFalse(im.visitdir(b'folder'))
self.assertFalse(im.visitdir(b'dir/subdir/z'))
self.assertFalse(im.visitdir(b'dir/subdir/x'))
def testVisitchildrensetIncludeInclude(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir'])
im = matchmod.intersectmatchers(m1, m2)
self.assertEqual(im.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(im.visitchildrenset(b'dir'), b'this')
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set())
self.assertEqual(im.visitchildrenset(b'dir/foo'), set())
self.assertEqual(im.visitchildrenset(b'folder'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set())
# We're using includematcher instead of patterns because it behaves slightly
# better (giving narrower results) than patternmatcher.
def testVisitdirIncludeInclude2(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'path:folder'])
im = matchmod.intersectmatchers(m1, m2)
# FIXME: is True correct here?
self.assertEqual(im.visitdir(b'.'), True)
self.assertFalse(im.visitdir(b'dir'))
self.assertFalse(im.visitdir(b'dir/subdir'))
self.assertFalse(im.visitdir(b'dir/foo'))
self.assertFalse(im.visitdir(b'folder'))
self.assertFalse(im.visitdir(b'dir/subdir/z'))
self.assertFalse(im.visitdir(b'dir/subdir/x'))
def testVisitchildrensetIncludeInclude2(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'path:folder'])
im = matchmod.intersectmatchers(m1, m2)
# FIXME: is set() correct here?
self.assertEqual(im.visitchildrenset(b'.'), set())
self.assertEqual(im.visitchildrenset(b'dir'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set())
self.assertEqual(im.visitchildrenset(b'dir/foo'), set())
self.assertEqual(im.visitchildrenset(b'folder'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set())
# We're using includematcher instead of patterns because it behaves slightly
# better (giving narrower results) than patternmatcher.
def testVisitdirIncludeInclude3(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x'])
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
im = matchmod.intersectmatchers(m1, m2)
self.assertEqual(im.visitdir(b'.'), True)
self.assertEqual(im.visitdir(b'dir'), True)
self.assertEqual(im.visitdir(b'dir/subdir'), True)
self.assertFalse(im.visitdir(b'dir/foo'))
self.assertFalse(im.visitdir(b'folder'))
self.assertFalse(im.visitdir(b'dir/subdir/z'))
# OPT: this should probably be 'all' not True.
self.assertEqual(im.visitdir(b'dir/subdir/x'), True)
def testVisitchildrensetIncludeInclude3(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x'])
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
im = matchmod.intersectmatchers(m1, m2)
self.assertEqual(im.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(im.visitchildrenset(b'dir/subdir'), {b'x'})
self.assertEqual(im.visitchildrenset(b'dir/foo'), set())
self.assertEqual(im.visitchildrenset(b'folder'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set())
# OPT: this should probably be 'all' not 'this'.
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this')
# We're using includematcher instead of patterns because it behaves slightly
# better (giving narrower results) than patternmatcher.
def testVisitdirIncludeInclude4(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x'])
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z'])
im = matchmod.intersectmatchers(m1, m2)
# OPT: these next three could probably be False as well.
self.assertEqual(im.visitdir(b'.'), True)
self.assertEqual(im.visitdir(b'dir'), True)
self.assertEqual(im.visitdir(b'dir/subdir'), True)
self.assertFalse(im.visitdir(b'dir/foo'))
self.assertFalse(im.visitdir(b'folder'))
self.assertFalse(im.visitdir(b'dir/subdir/z'))
self.assertFalse(im.visitdir(b'dir/subdir/x'))
def testVisitchildrensetIncludeInclude4(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x'])
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z'])
im = matchmod.intersectmatchers(m1, m2)
# OPT: these next two could probably be set() as well.
self.assertEqual(im.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set())
self.assertEqual(im.visitchildrenset(b'dir/foo'), set())
self.assertEqual(im.visitchildrenset(b'folder'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set())
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set())
class UnionMatcherTests(unittest.TestCase):
def testVisitdirM2always(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.alwaysmatcher(b'', b'')
um = matchmod.unionmatcher([m1, m2])
# um should be equivalent to a alwaysmatcher.
self.assertEqual(um.visitdir(b'.'), b'all')
self.assertEqual(um.visitdir(b'dir'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitdir(b'dir/foo'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all')
self.assertEqual(um.visitdir(b'folder'), b'all')
def testVisitchildrensetM2always(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.alwaysmatcher(b'', b'')
um = matchmod.unionmatcher([m1, m2])
# um should be equivalent to a alwaysmatcher.
self.assertEqual(um.visitchildrenset(b'.'), b'all')
self.assertEqual(um.visitchildrenset(b'dir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all')
self.assertEqual(um.visitchildrenset(b'folder'), b'all')
def testVisitdirM1never(self):
m1 = matchmod.nevermatcher(b'', b'')
m2 = matchmod.alwaysmatcher(b'', b'')
um = matchmod.unionmatcher([m1, m2])
# um should be equivalent to a alwaysmatcher.
self.assertEqual(um.visitdir(b'.'), b'all')
self.assertEqual(um.visitdir(b'dir'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitdir(b'dir/foo'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all')
self.assertEqual(um.visitdir(b'folder'), b'all')
def testVisitchildrensetM1never(self):
m1 = matchmod.nevermatcher(b'', b'')
m2 = matchmod.alwaysmatcher(b'', b'')
um = matchmod.unionmatcher([m1, m2])
# um should be equivalent to a alwaysmatcher.
self.assertEqual(um.visitchildrenset(b'.'), b'all')
self.assertEqual(um.visitchildrenset(b'dir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all')
self.assertEqual(um.visitchildrenset(b'folder'), b'all')
def testVisitdirM2never(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.nevermatcher(b'', b'')
um = matchmod.unionmatcher([m1, m2])
# um should be equivalent to a alwaysmatcher.
self.assertEqual(um.visitdir(b'.'), b'all')
self.assertEqual(um.visitdir(b'dir'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitdir(b'dir/foo'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all')
self.assertEqual(um.visitdir(b'folder'), b'all')
def testVisitchildrensetM2never(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.nevermatcher(b'', b'')
um = matchmod.unionmatcher([m1, m2])
# um should be equivalent to a alwaysmatcher.
self.assertEqual(um.visitchildrenset(b'.'), b'all')
self.assertEqual(um.visitchildrenset(b'dir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all')
self.assertEqual(um.visitchildrenset(b'folder'), b'all')
def testVisitdirM2SubdirPrefix(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir'])
um = matchmod.unionmatcher([m1, m2])
self.assertEqual(um.visitdir(b'.'), b'all')
self.assertEqual(um.visitdir(b'dir'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir'), b'all')
self.assertEqual(um.visitdir(b'dir/foo'), b'all')
self.assertEqual(um.visitdir(b'folder'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all')
def testVisitchildrensetM2SubdirPrefix(self):
m1 = matchmod.alwaysmatcher(b'', b'')
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
um = matchmod.unionmatcher([m1, m2])
self.assertEqual(um.visitchildrenset(b'.'), b'all')
self.assertEqual(um.visitchildrenset(b'dir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all')
self.assertEqual(um.visitchildrenset(b'folder'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all')
# We're using includematcher instead of patterns because it behaves slightly
# better (giving narrower results) than patternmatcher.
def testVisitdirIncludeIncludfe(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir'])
um = matchmod.unionmatcher([m1, m2])
self.assertEqual(um.visitdir(b'.'), True)
self.assertEqual(um.visitdir(b'dir'), True)
self.assertEqual(um.visitdir(b'dir/subdir'), b'all')
self.assertFalse(um.visitdir(b'dir/foo'))
self.assertFalse(um.visitdir(b'folder'))
# OPT: These two should probably be 'all' not True.
self.assertEqual(um.visitdir(b'dir/subdir/z'), True)
self.assertEqual(um.visitdir(b'dir/subdir/x'), True)
def testVisitchildrensetIncludeInclude(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir'])
um = matchmod.unionmatcher([m1, m2])
self.assertEqual(um.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(um.visitchildrenset(b'dir'), b'this')
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/foo'), set())
self.assertEqual(um.visitchildrenset(b'folder'), set())
# OPT: These next two could be 'all' instead of 'this'.
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this')
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this')
# We're using includematcher instead of patterns because it behaves slightly
# better (giving narrower results) than patternmatcher.
def testVisitdirIncludeInclude2(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'path:folder'])
um = matchmod.unionmatcher([m1, m2])
self.assertEqual(um.visitdir(b'.'), True)
self.assertEqual(um.visitdir(b'dir'), True)
self.assertEqual(um.visitdir(b'dir/subdir'), b'all')
self.assertFalse(um.visitdir(b'dir/foo'))
self.assertEqual(um.visitdir(b'folder'), b'all')
# OPT: These should probably be 'all' not True.
self.assertEqual(um.visitdir(b'dir/subdir/z'), True)
self.assertEqual(um.visitdir(b'dir/subdir/x'), True)
def testVisitchildrensetIncludeInclude2(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
m2 = matchmod.match(b'', b'', include=[b'path:folder'])
um = matchmod.unionmatcher([m1, m2])
self.assertEqual(um.visitchildrenset(b'.'), {b'folder', b'dir'})
self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/foo'), set())
self.assertEqual(um.visitchildrenset(b'folder'), b'all')
# OPT: These next two could be 'all' instead of 'this'.
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this')
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this')
# We're using includematcher instead of patterns because it behaves slightly
# better (giving narrower results) than patternmatcher.
def testVisitdirIncludeInclude3(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x'])
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
um = matchmod.unionmatcher([m1, m2])
self.assertEqual(um.visitdir(b'.'), True)
self.assertEqual(um.visitdir(b'dir'), True)
self.assertEqual(um.visitdir(b'dir/subdir'), b'all')
self.assertFalse(um.visitdir(b'dir/foo'))
self.assertFalse(um.visitdir(b'folder'))
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all')
# OPT: this should probably be 'all' not True.
self.assertEqual(um.visitdir(b'dir/subdir/z'), True)
def testVisitchildrensetIncludeInclude3(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x'])
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
um = matchmod.unionmatcher([m1, m2])
self.assertEqual(um.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/foo'), set())
self.assertEqual(um.visitchildrenset(b'folder'), set())
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all')
# OPT: this should probably be 'all' not 'this'.
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this')
# We're using includematcher instead of patterns because it behaves slightly
# better (giving narrower results) than patternmatcher.
def testVisitdirIncludeInclude4(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x'])
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z'])
um = matchmod.unionmatcher([m1, m2])
# OPT: these next three could probably be False as well.
self.assertEqual(um.visitdir(b'.'), True)
self.assertEqual(um.visitdir(b'dir'), True)
self.assertEqual(um.visitdir(b'dir/subdir'), True)
self.assertFalse(um.visitdir(b'dir/foo'))
self.assertFalse(um.visitdir(b'folder'))
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all')
def testVisitchildrensetIncludeInclude4(self):
m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x'])
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z'])
um = matchmod.unionmatcher([m1, m2])
self.assertEqual(um.visitchildrenset(b'.'), {b'dir'})
self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'})
self.assertEqual(um.visitchildrenset(b'dir/subdir'), {b'x', b'z'})
self.assertEqual(um.visitchildrenset(b'dir/foo'), set())
self.assertEqual(um.visitchildrenset(b'folder'), set())
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all')
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all')
class SubdirMatcherTests(unittest.TestCase):
def testVisitdir(self):
m = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
sm = matchmod.subdirmatcher(b'dir', m)
self.assertEqual(sm.visitdir(b'.'), True)
self.assertEqual(sm.visitdir(b'subdir'), b'all')
# OPT: These next two should probably be 'all' not True.
self.assertEqual(sm.visitdir(b'subdir/x'), True)
self.assertEqual(sm.visitdir(b'subdir/z'), True)
self.assertFalse(sm.visitdir(b'foo'))
def testVisitchildrenset(self):
m = matchmod.match(b'', b'', include=[b'path:dir/subdir'])
sm = matchmod.subdirmatcher(b'dir', m)
self.assertEqual(sm.visitchildrenset(b'.'), {b'subdir'})
self.assertEqual(sm.visitchildrenset(b'subdir'), b'all')
# OPT: These next two should probably be 'all' not 'this'.
self.assertEqual(sm.visitchildrenset(b'subdir/x'), b'this')
self.assertEqual(sm.visitchildrenset(b'subdir/z'), b'this')
self.assertEqual(sm.visitchildrenset(b'foo'), set())
class PrefixdirMatcherTests(unittest.TestCase):
def testVisitdir(self):
m = matchmod.match(util.localpath(b'root/d'), b'e/f',
[b'../a.txt', b'b.txt'])
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
# patterns are relative.
self.assertEqual(bool(m(b'a.txt')), False)
self.assertEqual(bool(m(b'b.txt')), False)
self.assertEqual(bool(m(b'e/a.txt')), True)
self.assertEqual(bool(m(b'e/b.txt')), False)
self.assertEqual(bool(m(b'e/f/b.txt')), True)
# The prefix matcher re-adds 'd' to the paths, so they need to be
# specified when using the prefixdirmatcher.
self.assertEqual(bool(pm(b'a.txt')), False)
self.assertEqual(bool(pm(b'b.txt')), False)
self.assertEqual(bool(pm(b'd/e/a.txt')), True)
self.assertEqual(bool(pm(b'd/e/b.txt')), False)
self.assertEqual(bool(pm(b'd/e/f/b.txt')), True)
self.assertEqual(m.visitdir(b'.'), True)
self.assertEqual(m.visitdir(b'e'), True)
self.assertEqual(m.visitdir(b'e/f'), True)
self.assertEqual(m.visitdir(b'e/f/g'), False)
self.assertEqual(pm.visitdir(b'.'), True)
self.assertEqual(pm.visitdir(b'd'), True)
self.assertEqual(pm.visitdir(b'd/e'), True)
self.assertEqual(pm.visitdir(b'd/e/f'), True)
self.assertEqual(pm.visitdir(b'd/e/f/g'), False)
def testVisitchildrenset(self):
m = matchmod.match(util.localpath(b'root/d'), b'e/f',
[b'../a.txt', b'b.txt'])
pm = matchmod.prefixdirmatcher(b'root', b'd/e/f', b'd', m)
# OPT: visitchildrenset could possibly return {'e'} and {'f'} for these
# next two, respectively; patternmatcher does not have this
# optimization.
self.assertEqual(m.visitchildrenset(b'.'), b'this')
self.assertEqual(m.visitchildrenset(b'e'), b'this')
self.assertEqual(m.visitchildrenset(b'e/f'), b'this')
self.assertEqual(m.visitchildrenset(b'e/f/g'), set())
# OPT: visitchildrenset could possibly return {'d'}, {'e'}, and {'f'}
# for these next three, respectively; patternmatcher does not have this
# optimization.
self.assertEqual(pm.visitchildrenset(b'.'), b'this')
self.assertEqual(pm.visitchildrenset(b'd'), b'this')
self.assertEqual(pm.visitchildrenset(b'd/e'), b'this')
self.assertEqual(pm.visitchildrenset(b'd/e/f'), b'this')
self.assertEqual(pm.visitchildrenset(b'd/e/f/g'), set())
if __name__ == '__main__':
silenttestrunner.main(__name__)