Added a clouple debug tools

This commit is contained in:
Maximilien Rigaut 2022-06-15 13:01:27 +02:00
parent 7f6a09097b
commit 8e97317b57
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
3 changed files with 41 additions and 3 deletions

View File

@ -86,6 +86,14 @@ class SemanticType:
def __ne__(self, other):
return not self.__eq__(other)
def __iter__(self):
"""
Iterator over the content of the token.
:yield: The iterator over the content of the token.
:ytype: iterable
"""
return iter(self.content)
def print_all(self, ident=0):
"""
Print all lines of the token.

View File

@ -174,6 +174,37 @@ def find_variables_in_file(file_path, list_variable_name): # pragma: no cover (
return find_string_in_file(file_path, [re.compile(f"^({variable_name}) ?=") for variable_name in list_variable_name])
def compare(me, other):
"""
Compares the container to another container.
:param me: The container to compare
:param other: The container to compare to
:type me: Container
:type other: Container
:return: True if the containers are equal, False otherwise
:rtype: bool
"""
import rich
from bootstraparse.modules import syntax, context_mngr
for e, f in zip(me, other):
if isinstance(e, context_mngr.BaseContainer) or isinstance(e, syntax.SemanticType):
compare(e, f)
elif e != f:
rich.print(f'elt:{e} != {f}')
return False
if hasattr(me, "optionals"):
if me.optionals != other.optionals:
rich.print(f'opt:{me.optionals} != {other.optionals}')
return False
if hasattr(me, "others"):
if me.others != other.others:
rich.print(f'oth:{me.others} != {other.others}')
return False
rich.print("No differences found")
return True
if __name__ == "__main__": # pragma: no cover
# print(find_string_in_file(__module_path("syntax.py"), [re.compile(r"^(html_insert) ?=")]))
pass

View File

@ -1,7 +1,7 @@
import pytest
import rich
from bootstraparse.modules import context_mngr, export, error_mngr
from bootstraparse.modules import context_mngr, export, error_mngr, tools
from bootstraparse.modules import syntax as sy #sy.SemanticType, sy.TextToken, sy.Linebreak, sy.StructuralElementStartToken, sy.StructuralElementEndToken, sy.EtUlistToken, sy.EtOlistToken # noqa
from bootstraparse.modules.tools import __GLk
__XF = pytest.mark.xfail
@ -646,8 +646,7 @@ def test_context_call(init_list, expected, file_line):
for i, e in zip(ctx(), expected):
# rich.inspect(i)
# rich.inspect(e)
i.print_all()
e.print_all()
tools.compare(i, e)
assert i == e
else:
with pytest.raises(expected[0]):