mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-23 01:20:03 +02:00
adds helper function to create config folder
This commit is contained in:
parent
9cbc639d0f
commit
4fcd5b4d44
@ -1,6 +1,7 @@
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -196,3 +197,9 @@ def get_data_service_class_reference() -> Any:
|
|||||||
|
|
||||||
def is_property_attribute(target_obj: Any, attr_name: str) -> bool:
|
def is_property_attribute(target_obj: Any, attr_name: str) -> bool:
|
||||||
return isinstance(getattr(type(target_obj), attr_name, None), property)
|
return isinstance(getattr(type(target_obj), attr_name, None), property)
|
||||||
|
|
||||||
|
|
||||||
|
def create_config_folder(config_dir: Path) -> None:
|
||||||
|
"""Create a configuration directory if it doesn't already exist."""
|
||||||
|
|
||||||
|
config_dir.mkdir(exist_ok=True)
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pydase.utils.helpers import is_property_attribute
|
from pydase.utils.helpers import (
|
||||||
|
create_config_folder,
|
||||||
|
is_property_attribute,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -26,3 +32,20 @@ def test_is_property_attribute(attr_name: str, expected: bool) -> None:
|
|||||||
|
|
||||||
dummy = DummyClass()
|
dummy = DummyClass()
|
||||||
assert is_property_attribute(dummy, attr_name) == expected
|
assert is_property_attribute(dummy, attr_name) == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_config_folder() -> None:
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
|
print("created temporary directory", tmpdirname)
|
||||||
|
|
||||||
|
config_dir = Path(tmpdirname) / "config"
|
||||||
|
|
||||||
|
assert not config_dir.exists()
|
||||||
|
|
||||||
|
create_config_folder(config_dir)
|
||||||
|
|
||||||
|
assert config_dir.exists()
|
||||||
|
|
||||||
|
# Call the function again to test idempotency (it should not fail if the
|
||||||
|
# directory already exists)
|
||||||
|
create_config_folder(config_dir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user