Loading pygriffin/config.py +7 −3 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from multiprocessing.sharedctypes import Value import os from pathlib import Path import subprocess import warnings try: from ConfigParser import ConfigParser Loading Loading @@ -31,7 +32,8 @@ class PyGriffinConfig: elif Path(__MOD_PATH.parent / '.pygriffin.rc').exists(): _RC_FILE = __MOD_PATH.parent / '.pygriffin.rc' else: raise RuntimeError('PyGriffin config file (.pygriffin.rc) could not be found.') _RC_FILE = None warnings.warn('PyGriffin config file (.pygriffin.rc) could not be found.') def __init__(self, griffin_exec=None, Loading @@ -41,6 +43,8 @@ class PyGriffinConfig: # always read the config file, # even if we don't use it self.__config = ConfigParser() if self._RC_FILE is not None: self.__config.read(str(self._RC_FILE)) self._griffin_exec = None Loading pygriffin/pygriffin.py +11 −6 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ class PyGriffin: p.wait() return p.returncode def process_xs(self, overwrite=False, particle='neutron', cwd=None): def process_xs(self, overwrite=True, particle='neutron', cwd=None): """ Runs ISOXML on the current set of cross sections Loading Loading @@ -148,16 +148,21 @@ class PyGriffin: "doesn't exist: {}".format(cwd)) raise ValueError(msg) # run isoxml executable on the current xs file cmd = [str(self.config.isoxml_exec), p_flag, str(self.xs)] p = subprocess.Popen(cmd, universal_newlines=True, cwd=str(cwd)) p.wait() # construct the name of the new xs file and return it name_parts = str(self.xs).split('.') name_parts[-1] = 'xml' xs_name = '.'.join(name_parts) xs_path = cwd / Path(xs_name) if overwrite and xs_path.exists(): warnings.warn("ISOXML output file already exists. Removing...") os.remove(xs_path) # run isoxml executable on the current xs file cmd = [str(self.config.isoxml_exec), p_flag, str(self.xs)] p = subprocess.Popen(cmd, universal_newlines=True, cwd=str(cwd)) p.wait() return xs_name def generate_mesh(self, overwrite=False): Loading tests/__init__.py +17 −0 Original line number Diff line number Diff line import os import pytest _SUSPEND_VARS = ('GRIFFIN_EXEC', 'ISOXML_EXEC') @pytest.fixture() def clean_env(): cache = {} for var in _SUSPEND_VARS: val = os.environ.pop(var, default=None) if val is not None: cache[var] = val yield # runs on test exit os.environ.update(cache) tests/test_no_config.py 0 → 100644 +23 −0 Original line number Diff line number Diff line import os import pytest import importlib from . import clean_env from pygriffin.pygriffin import PyGriffin, PyGriffinConfig def test_no_config(clean_env): # remove default .rc file location PyGriffinConfig._RC_FILE = "" # there should be no problem importing PyGriffin # with an empty configuration file, but trying to # create a PyGriffin instance should raise an exception with pytest.raises(RuntimeError) as e_info: pyg = PyGriffin(input='fake_input.i', mesh='fake_mesh.i') print(pyg.config.griffin_exec) Loading
pygriffin/config.py +7 −3 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from multiprocessing.sharedctypes import Value import os from pathlib import Path import subprocess import warnings try: from ConfigParser import ConfigParser Loading Loading @@ -31,7 +32,8 @@ class PyGriffinConfig: elif Path(__MOD_PATH.parent / '.pygriffin.rc').exists(): _RC_FILE = __MOD_PATH.parent / '.pygriffin.rc' else: raise RuntimeError('PyGriffin config file (.pygriffin.rc) could not be found.') _RC_FILE = None warnings.warn('PyGriffin config file (.pygriffin.rc) could not be found.') def __init__(self, griffin_exec=None, Loading @@ -41,6 +43,8 @@ class PyGriffinConfig: # always read the config file, # even if we don't use it self.__config = ConfigParser() if self._RC_FILE is not None: self.__config.read(str(self._RC_FILE)) self._griffin_exec = None Loading
pygriffin/pygriffin.py +11 −6 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ class PyGriffin: p.wait() return p.returncode def process_xs(self, overwrite=False, particle='neutron', cwd=None): def process_xs(self, overwrite=True, particle='neutron', cwd=None): """ Runs ISOXML on the current set of cross sections Loading Loading @@ -148,16 +148,21 @@ class PyGriffin: "doesn't exist: {}".format(cwd)) raise ValueError(msg) # run isoxml executable on the current xs file cmd = [str(self.config.isoxml_exec), p_flag, str(self.xs)] p = subprocess.Popen(cmd, universal_newlines=True, cwd=str(cwd)) p.wait() # construct the name of the new xs file and return it name_parts = str(self.xs).split('.') name_parts[-1] = 'xml' xs_name = '.'.join(name_parts) xs_path = cwd / Path(xs_name) if overwrite and xs_path.exists(): warnings.warn("ISOXML output file already exists. Removing...") os.remove(xs_path) # run isoxml executable on the current xs file cmd = [str(self.config.isoxml_exec), p_flag, str(self.xs)] p = subprocess.Popen(cmd, universal_newlines=True, cwd=str(cwd)) p.wait() return xs_name def generate_mesh(self, overwrite=False): Loading
tests/__init__.py +17 −0 Original line number Diff line number Diff line import os import pytest _SUSPEND_VARS = ('GRIFFIN_EXEC', 'ISOXML_EXEC') @pytest.fixture() def clean_env(): cache = {} for var in _SUSPEND_VARS: val = os.environ.pop(var, default=None) if val is not None: cache[var] = val yield # runs on test exit os.environ.update(cache)
tests/test_no_config.py 0 → 100644 +23 −0 Original line number Diff line number Diff line import os import pytest import importlib from . import clean_env from pygriffin.pygriffin import PyGriffin, PyGriffinConfig def test_no_config(clean_env): # remove default .rc file location PyGriffinConfig._RC_FILE = "" # there should be no problem importing PyGriffin # with an empty configuration file, but trying to # create a PyGriffin instance should raise an exception with pytest.raises(RuntimeError) as e_info: pyg = PyGriffin(input='fake_input.i', mesh='fake_mesh.i') print(pyg.config.griffin_exec)