Commit 9060e369 authored by Stauff, Nicolas Emile's avatar Stauff, Nicolas Emile
Browse files

Merge branch 'fixes' into 'development'

ISOXML overwrite and configuration fixes

See merge request nstauff/PyGriffin!14
parents 06339e49 085dc3f4
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ from multiprocessing.sharedctypes import Value
import os
from pathlib import Path
import subprocess
import warnings

try:
    from ConfigParser import ConfigParser
@@ -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,
@@ -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
+11 −6
Original line number Diff line number Diff line
@@ -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

@@ -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):
+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)
+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)