From dbce29665592ebdc9916678b83fab61a84962754 Mon Sep 17 00:00:00 2001 From: Andrew Porter Date: Wed, 15 Jan 2025 15:34:28 +0000 Subject: [PATCH] #2845 get coverge for new branch in SymbolTable --- src/psyclone/psyir/symbols/symbol_table.py | 8 ++++---- .../tests/psyir/symbols/symbol_table_test.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/psyclone/psyir/symbols/symbol_table.py b/src/psyclone/psyir/symbols/symbol_table.py index 6d388ba731..9c45b5f3ba 100644 --- a/src/psyclone/psyir/symbols/symbol_table.py +++ b/src/psyclone/psyir/symbols/symbol_table.py @@ -1583,12 +1583,12 @@ def resolve_imports(self, container_symbols=None, symbol_target=None): :type symbol_target: Optional[ :py:class:`psyclone.psyir.symbols.Symbol`] - :raises SymbolError: if a symbol name clash is found between multiple \ + :raises SymbolError: if a symbol name clash is found between multiple imports or an import and a local symbol. - :raises TypeError: if the provided container_symbols is not a list of \ + :raises TypeError: if the provided container_symbols is not a list of ContainerSymbols. :raises TypeError: if the provided symbol_target is not a Symbol. - :raises KeyError: if a symbol_target has been specified but this has \ + :raises KeyError: if a symbol_target has been specified but this has not been found in any of the searched containers. ''' @@ -1617,7 +1617,7 @@ def resolve_imports(self, container_symbols=None, symbol_target=None): try: external_container = c_symbol.find_container_psyir( local_node=self.node) - # pylint: disable=broad-except + # pylint: disable-next=broad-except except Exception: # Ignore this container if the associated module file has not # been found in the given include_path or any issue has arisen diff --git a/src/psyclone/tests/psyir/symbols/symbol_table_test.py b/src/psyclone/tests/psyir/symbols/symbol_table_test.py index 6e29095b56..f220e7b8f9 100644 --- a/src/psyclone/tests/psyir/symbols/symbol_table_test.py +++ b/src/psyclone/tests/psyir/symbols/symbol_table_test.py @@ -2877,6 +2877,20 @@ def test_resolve_imports(fortran_reader, tmpdir, monkeypatch): assert a_2.visibility == symbols.Symbol.Visibility.PRIVATE +def test_resolve_imports_missing_container(monkeypatch): + ''' + Test that a clean failure to get Container PSyIR does not cause problems. + ''' + table = symbols.SymbolTable() + csym = symbols.ContainerSymbol("a_mod") + # Monkeypatch the find_container_psyir() method of this ContainerSymbol + # so that it returns None. + monkeypatch.setattr(csym, "find_container_psyir", lambda local_node: None) + table.add(csym) + # Resolving imports should run without problems. + table.resolve_imports() + + @pytest.mark.usefixtures("clear_module_manager_instance") def test_resolve_imports_different_capitalization( fortran_reader, tmpdir, monkeypatch):