From dc2f6fd04a556bffb816ba8881dc2b1452b8247e Mon Sep 17 00:00:00 2001 From: Kodjo Sossouvi Date: Sun, 9 Nov 2025 11:23:20 +0100 Subject: [PATCH] Fixed ErrorOutput when special children --- src/myfasthtml/test/matcher.py | 41 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/myfasthtml/test/matcher.py b/src/myfasthtml/test/matcher.py index 1971dd8..bb7ee78 100644 --- a/src/myfasthtml/test/matcher.py +++ b/src/myfasthtml/test/matcher.py @@ -129,7 +129,7 @@ class ErrorOutput: return item, None, None def __str__(self): - self.compute() + return f"ErrorOutput({self.output})" def compute(self): # first render the path hierarchy @@ -156,27 +156,26 @@ class ErrorOutput: self.indent += " " element_index = 0 for expected_child in expected_children: - if hasattr(expected_child, "tag"): - if element_index < len(self.element.children): - # display the child - element_child = self.element.children[element_index] - child_str = self._str_element(element_child, expected_child, keep_open=False) - self._add_to_output(child_str) - - # manage errors in children - child_error_str = self._detect_error(element_child, expected_child) - if child_error_str: - self._add_to_output(child_error_str) - element_index += 1 - - else: - # When there are fewer children than expected, we display a placeholder - child_str = "! ** MISSING ** !" - self._add_to_output(child_str) + if element_index >= len(self.element.children): + # When there are fewer children than expected, we display a placeholder + child_str = "! ** MISSING ** !" + self._add_to_output(child_str) + element_index += 1 + continue - else: - if expected_child in self.element.children: - self._add_to_output(expected_child) + # display the child + element_child = self.element.children[element_index] + child_str = self._str_element(element_child, expected_child, keep_open=False) + self._add_to_output(child_str) + + # manage errors (only when the expected is a FT element + if hasattr(expected_child, "tag"): + child_error_str = self._detect_error(element_child, expected_child) + if child_error_str: + self._add_to_output(child_error_str) + + # continue + element_index += 1 self.indent = self.indent[:-2] self._add_to_output(")")