mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Add tests for openmc.config
This commit is contained in:
parent
ab6f9247ca
commit
35930e0422
2 changed files with 45 additions and 1 deletions
|
|
@ -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()
|
||||
|
|
|
|||
43
tests/unit_tests/test_config.py
Normal file
43
tests/unit_tests/test_config.py
Normal file
|
|
@ -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'
|
||||
Loading…
Add table
Add a link
Reference in a new issue