diff --git a/openmc/config.py b/openmc/config.py index 08b8c3cb64..fe7c5aa06e 100644 --- a/openmc/config.py +++ b/openmc/config.py @@ -33,6 +33,7 @@ class _Config(MutableMapping): os.environ['OPENMC_MG_CROSS_SECTIONS'] = str(value) elif key == 'chain_file': self._set_path(key, value) + os.environ['OPENMC_CHAIN_FILE'] = str(value) else: raise KeyError(f'Unrecognized config key: {key}') @@ -62,7 +63,7 @@ def _default_config(): config['mg_cross_sections'] = os.environ["OPENMC_MG_CROSS_SECTIONS"] # Set depletion chain - chain_file = os.environ.get("OPENMC_DEPLETE_CHAIN") + chain_file = os.environ.get("OPENMC_CHAIN_FILE") if (chain_file is None and config['cross_sections'] is not None and config['cross_sections'].exists() diff --git a/tests/unit_tests/test_config.py b/tests/unit_tests/test_config.py new file mode 100644 index 0000000000..1d3c0f173b --- /dev/null +++ b/tests/unit_tests/test_config.py @@ -0,0 +1,43 @@ +from collections.abc import Mapping +import os + +import openmc +import pytest + + +@pytest.fixture(autouse=True, scope='module') +def reset_config(): + config = dict(openmc.config) + try: + yield + finally: + openmc.config.clear() + openmc.config.update(config) + + +def test_config_basics(): + assert isinstance(openmc.config, Mapping) + for key, value in openmc.config.items(): + assert isinstance(key, str) + assert isinstance(value, os.PathLike) + + # Set and delete + openmc.config['cross_sections'] = '/path/to/cross_sections.xml' + del openmc.config['cross_sections'] + assert 'cross_sections' not in openmc.config + assert 'OPENMC_CROSS_SECTIONS' not in os.environ + + # Can't use any key + with pytest.raises(KeyError): + openmc.config['🐖'] = '/like/to/eat/bacon' + + +def test_config_set_envvar(): + openmc.config['cross_sections'] = '/path/to/cross_sections.xml' + assert os.environ['OPENMC_CROSS_SECTIONS'] == '/path/to/cross_sections.xml' + + openmc.config['mg_cross_sections'] = '/path/to/mg_cross_sections.h5' + assert os.environ['OPENMC_MG_CROSS_SECTIONS'] == '/path/to/mg_cross_sections.h5' + + openmc.config['chain_file'] = '/path/to/chain_file.xml' + assert os.environ['OPENMC_CHAIN_FILE'] == '/path/to/chain_file.xml'