Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that cache_enable propagates to the end of UIAElementInfo.iter_descendants #1334

Open
wants to merge 5 commits into
base: atspi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pywinauto/unittests/test_uia_element_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ def test_descendants_generator(self):
descendants = [desc for desc in self.ctrl.iter_descendants(depth=3)]
self.assertSequenceEqual(self.ctrl.descendants(depth=3), descendants)

def test_cache_enabled_children(self):
"""Test whether `cache_enable=True` are propagated to children"""
children = self.ctrl.children(cache_enable=True)
for c in children:
self.assertEqual(c._get_class_name, c._get_cached_class_name)

def test_cache_enabled_children_generator(self):
"""Test whether `cache_enable=True` are propagated to children generator"""
children = self.ctrl.iter_children(cache_enable=True)
for c in children:
self.assertEqual(c._get_class_name, c._get_cached_class_name)

def test_cache_enabled_descendants(self):
"""Test whether `cache_enable=True` are propagated to descendants"""
descendants = self.ctrl.descendants(cache_enable=True)
for d in descendants:
self.assertEqual(d._get_class_name, d._get_cached_class_name)

def test_cache_enabled_descendants_generator(self):
"""Test whether `cache_enable=True` are propagated to descendants generator"""
descendants = self.ctrl.iter_descendants(cache_enable=True)
for d in descendants:
self.assertEqual(d._get_class_name, d._get_cached_class_name)

class UIAElementInfoRawViewWalkerTests(UIAElementInfoTests):

Expand Down
18 changes: 9 additions & 9 deletions pywinauto/windows/uia_element_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def iter_children(self, **kwargs):
tree_walker = IUIA().iuia.CreateTreeWalker(cond)
element = tree_walker.GetFirstChildElement(self._element)
while element:
yield UIAElementInfo(element)
yield UIAElementInfo(element, cache_enable)
element = tree_walker.GetNextSiblingElement(element)

def iter_descendants(self, **kwargs):
Expand All @@ -442,20 +442,20 @@ def iter_descendants(self, **kwargs):
if depth == 0:
return
if UIAElementInfo.use_raw_view_walker:
for child in self._iter_children_raw():
if is_element_satisfying_criteria(child, **kwargs):
yield UIAElementInfo(child, cache_enable)
for raw_child in self._iter_children_raw():
child = UIAElementInfo(raw_child, cache_enable)
if is_element_satisfying_criteria(raw_child, **kwargs):
yield child
if depth is not None:
kwargs["depth"] = depth - 1
for c in UIAElementInfo(child, cache_enable).iter_descendants(**kwargs):
if is_element_satisfying_criteria(c._element, **kwargs):
yield c
for c in child.iter_descendants(cache_enable=cache_enable, **kwargs):
yield c
else:
for child in self.iter_children(**kwargs):
for child in self.iter_children(cache_enable=cache_enable, **kwargs):
yield child
if depth is not None:
kwargs["depth"] = depth - 1
for c in child.iter_descendants(**kwargs):
for c in child.iter_descendants(cache_enable=cache_enable, **kwargs):
yield c

def children(self, **kwargs):
Expand Down
Loading