nwb-linkml/nwb_linkml/tests/test_config.py

37 lines
845 B
Python
Raw Permalink Normal View History

import os
import shutil
2024-07-02 04:44:35 +00:00
import tempfile
from pathlib import Path
from nwb_linkml.config import Config
def test_config_dir():
"""Ensure that the temporary directory is the same across multiple instantiations of the singleton-like config object"""
c1 = Config()
c2 = Config()
assert c1.cache_dir == c2.cache_dir
2024-07-02 04:23:31 +00:00
def test_config_env():
"""
Base cache dir can be overridden by environmental variable
"""
2024-07-02 04:23:31 +00:00
orig_env = os.environ["NWB_LINKML_CACHE_DIR"]
2024-07-02 04:23:31 +00:00
new_temp = Path(tempfile.gettempdir()) / "test_tmp_dir"
new_temp.mkdir()
try:
assert Path(orig_env) != new_temp
2024-07-02 04:23:31 +00:00
os.environ["NWB_LINKML_CACHE_DIR"] = str(new_temp)
conf = Config()
assert conf.cache_dir == new_temp
finally:
shutil.rmtree(new_temp)
2024-07-02 04:23:31 +00:00
os.environ["NWB_LINKML_CACHE_DIR"] = orig_env