Repository: CORE-GATECH-GROUP/serpent-tools
Pull request #347 (2019-10-09 13:49:06)

BUG Correctly get variable groups for version 2.1.31
The lack of a 2.1.31 block in variables.yaml meant that if the
user specified
```
rc["serpentVersion"] = "2.1.31"  # also the default!!
rc["variableGroups"] = ["six-ff", "n-balance"]
```
the six factor formula information would not be expanded. Furthermore,
since 2.1.31 and the base [2.1.29] differ in the neutron balance data,
some information would be missing.

This commit adds the 2.1.30 group as an anchor in variables.yaml
that 2.1.31 references. This means we don't have to re-write the
whole block. Did have to change 2.1.30 -> 2-1-30 in the file as
only alphanumeric characters are allowed for yaml anchors.

A test has been added for this expansion, and the variable group
documentation has been updated.


Patch:
diff --git a/docs/variableGroups.rst b/docs/variableGroups.rst
index 70d9b7b..87feb69 100644
--- a/docs/variableGroups.rst
+++ b/docs/variableGroups.rst
@@ -1,3 +1,12 @@
+.. _vars-2-1-31:
+
+----------
+``2.1.31``
+----------
+
+Variable groups for Serpent 2.1.31 are identical to those from 
+Serpent 2.1.30
+
 .. _vars-2-1-30:
 
 ----------
diff --git a/serpentTools/settings.py b/serpentTools/settings.py
index 58fb815..cad510a 100644
--- a/serpentTools/settings.py
+++ b/serpentTools/settings.py
@@ -364,7 +364,7 @@ class UserSettingsLoader(dict):
            """
         keywords = self['xs.variableGroups']
         extras = self['xs.variableExtras']
-        serpentVersion = self['serpentVersion']
+        serpentVersion = self['serpentVersion'].replace(".", "-")
         if not (keywords or extras):  # return empty set and don't read
             return set()
         variables = set(extras) if extras else set()
@@ -376,10 +376,12 @@ class UserSettingsLoader(dict):
         thisVersion = groups.get(serpentVersion, {})
         baseGroups = groups['base']
         for key in keywords:
-            if key in thisVersion:
-                variables.update(thisVersion[key])
-            elif key in baseGroups:
-                variables.update(baseGroups[key])
+            versionVars = thisVersion.get(key)
+            baseVars = baseGroups.get(key)
+            if versionVars:
+                variables.update(versionVars)
+            elif baseVars:
+                variables.update(baseVars)
         return variables
 
     def loadYaml(self, filePath, strict=True):
diff --git a/serpentTools/variables.yaml b/serpentTools/variables.yaml
index 0f9584a..ea833a9 100644
--- a/serpentTools/variables.yaml
+++ b/serpentTools/variables.yaml
@@ -110,7 +110,7 @@ base:
     {ALB_SURFACE, ALB_FLIP_DIR, ALB_N_SURF, ALB_IN_CURR, ALB_OUT_CURR, 
     ALB_TOT_ALB, ALB_PART_ALB}
 
-2.1.30:
+2-1-30: &2-1-30
   n-balance: !!set 
     {BALA_SRC_NEUTRON_SRC, BALA_SRC_NEUTRON_FISS, BALA_SRC_NEUTRON_NXN,
      BALA_SRC_NEUTRON_VR, BALA_SRC_NEUTRON_TOT, BALA_LOSS_NEUTRON_CAPT,
@@ -129,3 +129,5 @@ base:
   six-ff: !!set
       {SIX_FF_EPSILON, SIX_FF_ETA, SIX_FF_F, SIX_FF_KEFF, SIX_FF_KINF,
       SIX_FF_LT, SIX_FF_LF, SIX_FF_P}
+
+2-1-31: *2-1-30


Test patch:
diff --git a/tests/test_variables.py b/tests/test_variables.py
new file mode 100644
index 0000000..301ccc7
--- /dev/null
+++ b/tests/test_variables.py
@@ -0,0 +1,25 @@
+"""
+Some tests for the setting of variable extras and groups
+"""
+
+import pytest
+import serpentTools.settings
+
+@pytest.fixture
+def tempRC():
+    """Provide an RC object that is reset after each test"""
+    with serpentTools.settings.rc as temp:
+        yield temp
+
+
+@pytest.mark.parametrize("version", ["2.1.30", "2.1.31"])
+def test_variableGroups(tempRC, version):
+    tempRC["serpentVersion"] = version
+    tempRC["xs.variableGroups"] = ["six-ff", "eig"]
+
+    expected = {"SIX_FF_" + s for s in {
+        "EPSILON", "ETA", "F", "KEFF", "KINF", "LT", "LF", "P"}}
+    expected.update({
+        "ANA_KEFF", "IMP_KEFF", "COL_KEFF", "ABS_KEFF", "ABS_KINF",
+        "GEOM_ALBEDO"})
+    assert expected == tempRC.expandVariables()