mirror of
https://github.com/p2p-ld/nwb-linkml.git
synced 2024-11-10 08:44:30 +00:00
38 lines
859 B
Python
38 lines
859 B
Python
|
import pytest
|
||
|
import tempfile
|
||
|
from pathlib import Path
|
||
|
import os
|
||
|
import shutil
|
||
|
|
||
|
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
|
||
|
|
||
|
def test_config_env():
|
||
|
"""
|
||
|
Base cache dir can be overridden by environmental variable
|
||
|
"""
|
||
|
|
||
|
orig_env = os.environ['NWB_LINKML_CACHE_DIR']
|
||
|
|
||
|
new_temp = Path(tempfile.gettempdir()) / 'test_tmp_dir'
|
||
|
new_temp.mkdir()
|
||
|
|
||
|
try:
|
||
|
assert Path(orig_env) != new_temp
|
||
|
|
||
|
os.environ['NWB_LINKML_CACHE_DIR'] = str(new_temp)
|
||
|
|
||
|
conf = Config()
|
||
|
|
||
|
assert conf.cache_dir == new_temp
|
||
|
finally:
|
||
|
shutil.rmtree(new_temp)
|
||
|
os.environ['NWB_LINKML_CACHE_DIR'] = orig_env
|
||
|
|