Skip to content

Commit

Permalink
fix #4, fix #203 - extend testing, fix recursion issue
Browse files Browse the repository at this point in the history
  • Loading branch information
c0fec0de committed Oct 11, 2023
1 parent 4956082 commit d18be95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions anytree/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import re

from .config import ASSERTIONS
from anytree.iterators.preorderiter import PreOrderIter

from .config import ASSERTIONS

_MAXCACHE = 20


Expand Down Expand Up @@ -228,9 +229,11 @@ def __glob(self, node, parts):
# handle recursive
if name == "**":
matches = []
for n in PreOrderIter(node):
for subnode in PreOrderIter(node):
try:
matches += self.__glob(n, remainder)
for match in self.__glob(subnode, remainder):
if match not in matches:
matches.append(match)
except ChildResolverError:
pass
return matches
Expand Down
2 changes: 1 addition & 1 deletion tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def eq_(one, other):
assert one == other
assert one == other, "{one} != {other}".format(one=one, other=other)


# hack own assert_raises, because py26 has a different impelmentation
Expand Down
7 changes: 6 additions & 1 deletion tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ def test_glob():
r.glob(sub1, "/z*")

# Recursive matching
eq_(r.glob(top, "**/sub0"), [sub0, sub0sub0, sub0sub1sub0, sub1sub0])
assert r.glob(top, "**/sub0") == [sub0, sub0sub0, sub0sub1sub0, sub1sub0]
assert r.glob(top, "**/sub0/sub0") == [sub0sub0]
assert r.glob(top, "**/**/sub0") == [sub0, sub0sub0, sub0sub1sub0, sub1sub0]
assert r.glob(top, "sub0/**/sub0") == [sub0sub0, sub0sub1sub0]
with assert_raises(at.ResolverError, "unknown root node '/sub0'. root is '/top'."):
r.glob(top, "/sub0/**/sub0")


def test_glob_cache():
Expand Down

0 comments on commit d18be95

Please sign in to comment.