Purged the list after matching
This commit is contained in:
parent
eee8e2b3fc
commit
70e5d4545f
|
|
@ -408,8 +408,8 @@ class ContextManager:
|
|||
raise error
|
||||
for i in range(start, end):
|
||||
if self.pile[i]:
|
||||
container.add(self.pile[i].to_container(lambda x: x.label==pile_start.label)) # This line transform the self modifiying containers # MONITOR # noqa
|
||||
#container.add(self.pile[i]) # TODO: ignore the first and last element, or ignore the self modifying tokens # noqa : F821
|
||||
# This line transform the self modifiying containers # MONITOR
|
||||
container.add(self.pile[i].to_container(lambda x: x.label == pile_start.label)) # noqa : F821
|
||||
self.pile[i] = None
|
||||
container.add(self.pile[end])
|
||||
self.pile[end] = None
|
||||
|
|
@ -497,11 +497,15 @@ class ContextManager:
|
|||
final_pile = []
|
||||
for p in self.pile:
|
||||
if p is not None:
|
||||
final_pile.append(p)
|
||||
|
||||
if isinstance(p, BaseContainer):
|
||||
final_pile.append(p)
|
||||
else: # Cleanup of non-matched elements
|
||||
log_exception(
|
||||
TypeError(f"Expected BaseContainer, found {type(p)} instead."),
|
||||
level="CRITICAL"
|
||||
)
|
||||
self.pile = final_pile
|
||||
|
||||
# TODO: add cleanup of non-matched elements
|
||||
return self.pile
|
||||
|
||||
def lookahead(self, token, index):
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ def log_exception(exception, level="ERROR"):
|
|||
logging.__getattribute__(level)(' ' + line)
|
||||
if level in ["critical", "error"]:
|
||||
print("An unrecoverable error occurred, please check the log file for more information.")
|
||||
raise exception # TODO: drop the last stack
|
||||
raise exception # FUTURE: drop the last stack
|
||||
|
||||
if exception.__class__.__name__ == "ParsingError":
|
||||
logging.error(exception.__str__())
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ if __name__ == "__main__":
|
|||
_env.config = config.ConfigLoader(config_path)
|
||||
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
|
||||
__templates = config.ConfigLoader(pathresolver.b_path("templates/"))
|
||||
_env.export_mngr = export.ExportManager('', '', __config, __templates)
|
||||
_env.export_mngr = export.ExportManager(__config, __templates)
|
||||
xpath = pathresolver.b_path("../../example_userfiles")
|
||||
dpath = pathresolver.b_path("../../example_output")
|
||||
sc = SiteCrawler(xpath, dpath, _env)
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@ _zipped_token_list_with_expected_result = [
|
|||
def base_cm():
|
||||
lst = _base_list[:]
|
||||
base = context_mngr.ContextManager(_base_list)
|
||||
base.pile = lst
|
||||
base()
|
||||
return base
|
||||
|
||||
|
||||
|
|
@ -475,16 +475,8 @@ def test_container_init(cls):
|
|||
cls()
|
||||
|
||||
|
||||
def test_context_manager(base_cm):
|
||||
lst = [sy.SemanticType(["1"]), sy.SemanticType([2]), sy.SemanticType([3])]
|
||||
base = context_mngr.ContextManager(lst)
|
||||
base.pile = lst
|
||||
|
||||
for e, v in zip(_base_list, base_cm):
|
||||
assert e == v
|
||||
|
||||
|
||||
def test_encapsulate(base_cm): # Robustness is tested in test_container_export_value
|
||||
base_cm.pile = _base_list[:]
|
||||
base_cm.encapsulate(1, 2)
|
||||
ctn = context_mngr.TextContainer()
|
||||
ctn.add(_base_list[1])
|
||||
|
|
@ -494,6 +486,7 @@ def test_encapsulate(base_cm): # Robustness is tested in test_container_export_
|
|||
|
||||
|
||||
def test_encapsulate_bad_index(base_cm):
|
||||
base_cm.pile = _base_list[:]
|
||||
with pytest.raises(IndexError):
|
||||
base_cm.encapsulate(1, 44)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue