Added a clouple debug tools
This commit is contained in:
parent
7f6a09097b
commit
8e97317b57
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]):
|
||||
|
|
|
|||
Loading…
Reference in New Issue