diff --git a/src/bootstraparse/modules/context_mngr.py b/src/bootstraparse/modules/context_mngr.py index ae7a81d..5554708 100644 --- a/src/bootstraparse/modules/context_mngr.py +++ b/src/bootstraparse/modules/context_mngr.py @@ -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): diff --git a/src/bootstraparse/modules/error_mngr.py b/src/bootstraparse/modules/error_mngr.py index e3fc36d..d0b69f4 100644 --- a/src/bootstraparse/modules/error_mngr.py +++ b/src/bootstraparse/modules/error_mngr.py @@ -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__()) diff --git a/src/bootstraparse/modules/sitecrawler.py b/src/bootstraparse/modules/sitecrawler.py index 9175e11..69c6a6a 100644 --- a/src/bootstraparse/modules/sitecrawler.py +++ b/src/bootstraparse/modules/sitecrawler.py @@ -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) diff --git a/tests/modules/test_context_mngr.py b/tests/modules/test_context_mngr.py index bad49d7..87bd094 100644 --- a/tests/modules/test_context_mngr.py +++ b/tests/modules/test_context_mngr.py @@ -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)