Skip to content

Commit

Permalink
Merge pull request #120 from sudlab/ns-rse/119-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-rse authored Dec 13, 2024
2 parents 74314cf + 7e359d5 commit 3a36926
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
22 changes: 19 additions & 3 deletions isoslam/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
"""Utilities and helper functionsfor IsoSLAM."""

from argparse import Namespace
from pathlib import Path

from loguru import logger

from isoslam import io

def convert_path(path: str | Path) -> Path:
"""
Ensure path is Path object.
Parameters
----------
path : str | Path
Path to be converted.
Returns
-------
Path
Pathlib object of path.
"""
return Path().cwd() if path == "./" else Path(path).expanduser()


def update_config(config: dict, args: dict | Namespace) -> dict: # type: ignore[type-arg]
Expand Down Expand Up @@ -35,7 +51,7 @@ def update_config(config: dict, args: dict | Namespace) -> dict: # type: ignore
config[arg_key] = arg_value
logger.debug(f"Updated config config[{arg_key}] : {original_value} > {arg_value} ")
if "base_dir" in config.keys():
config["base_dir"] = io._str_to_path(config["base_dir"]) # pylint: disable=protected-access
config["base_dir"] = convert_path(config["base_dir"]) # pylint: disable=protected-access
if "output_dir" in config.keys():
config["output_dir"] = io._str_to_path(config["output_dir"]) # pylint: disable=protected-access
config["output_dir"] = convert_path(config["output_dir"]) # pylint: disable=protected-access
return config
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
),
],
)
def test_update_config(
sample_config: dict, new_values: dict, expected_config: dict, caplog: pytest.LogCaptureFixture
) -> None:
def test_update_config(sample_config: dict, new_values: dict, expected_config: dict) -> None:
"""Test updating configuration."""
updated_config = utils.update_config(sample_config, new_values)

assert isinstance(updated_config, dict)
assert updated_config == expected_config
assert isinstance(updated_config["base_dir"], Path)
assert isinstance(updated_config["output_dir"], Path)

0 comments on commit 3a36926

Please sign in to comment.