From 2bc401f04e28abde686efab1d39ea1888fbcb947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Andr=C3=A9s=20Marino=20Rojas?= <47573394+Marinovsky@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:54:11 -0500 Subject: [PATCH] Improve implementation --- lean/components/config/lean_config_manager.py | 4 ++-- tests/components/config/test_lean_config_manager.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lean/components/config/lean_config_manager.py b/lean/components/config/lean_config_manager.py index 0a765922..aa26ab16 100644 --- a/lean/components/config/lean_config_manager.py +++ b/lean/components/config/lean_config_manager.py @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from os.path import normcase +from os.path import normcase, normpath from pathlib import Path from typing import Any, Dict, Optional, List @@ -98,7 +98,7 @@ def get_known_lean_config_paths(self) -> List[Path]: :return: a list of paths to Lean config files that were used in the past """ lean_config_paths = self._cache_storage.get("known-lean-config-paths", []) - lean_config_paths = [Path(normcase(p)) for p in lean_config_paths if Path(p).is_file()] + lean_config_paths = [Path(normpath(normcase(p))) for p in lean_config_paths if Path(p).is_file()] lean_config_paths = list(set(lean_config_paths)) self._cache_storage.set("known-lean-config-paths", [str(p) for p in lean_config_paths]) diff --git a/tests/components/config/test_lean_config_manager.py b/tests/components/config/test_lean_config_manager.py index 7ea51e20..ee7dcd99 100644 --- a/tests/components/config/test_lean_config_manager.py +++ b/tests/components/config/test_lean_config_manager.py @@ -100,6 +100,16 @@ def test_get_known_lean_config_path_with_duplicated_paths() -> None: assert manager.get_known_lean_config_paths() == [Path.cwd() / "custom-lean.json"] +def test_get_known_lean_config_path_normalizes_path_and_case() -> None: + custom_config_path = Path.cwd() / "//folder//..//custom-lean.json//" + custom_config_path.touch() + custom_config_path.write_text("{}", encoding="utf-8") + + manager = _create_lean_config_manager() + manager.set_default_lean_config_path(custom_config_path) + + assert manager.get_known_lean_config_paths() == [Path(os.path.normcase(Path.cwd() / "/custom-lean.json"))] + def test_get_cli_root_directory_returns_path_to_directory_containing_config_file() -> None: create_fake_lean_cli_directory()