Repository: ESMCI/cime

Issue:
Add "set_value" method to CIME.BuildTools.configure.FakeCase so that user can add needed variables
In principle this is a simple change, but I want to make sure it's acceptable. I'd like to add a set_value method to the FakeCase class in CIME.BuiltTools.configure so that the user can add the variables they want to have in their FakeCase. The utility I see is for unit-testing of buildnml. But, I think there may be other cases where you want to create a simpler Fake case without doing all the normal needed setup to create a real case. There are some offline scripts we are thinking about having this kind of utility where we know we need to setup some type of fake case, but we want to hide it from the user, and it doesn't need to be fully functional like a real case.

``` python
diff --git a/scripts/lib/CIME/BuildTools/configure.py b/scripts/lib/CIME/BuildTools/configure.py
index a74c087a5..fd7067ed7 100644
--- a/scripts/lib/CIME/BuildTools/configure.py
+++ b/scripts/lib/CIME/BuildTools/configure.py
@@ -74,6 +74,9 @@ def get_value(self, attrib):
         expect(attrib in self._vals, "FakeCase does not support getting value of '%s'" % attrib)
         return self._vals[attrib]
 
+    def set_value(self, attrib, value):
+       self._vals[attrib] = value
+
 def _generate_env_mach_specific(output_dir, machobj, compiler, mpilib, debug,
                                 sysos, unit_testing):
     """
```

@jedwards4b does this sound acceptable? If so I'll submit a simple PR for it.
@billsacks would this kind of thing possibly make LILAC easier to setup?
Add "set_value" method to CIME.BuildTools.configure.FakeCase so that user can add needed variables
In principle this is a simple change, but I want to make sure it's acceptable. I'd like to add a set_value method to the FakeCase class in CIME.BuiltTools.configure so that the user can add the variables they want to have in their FakeCase. The utility I see is for unit-testing of buildnml. But, I think there may be other cases where you want to create a simpler Fake case without doing all the normal needed setup to create a real case. There are some offline scripts we are thinking about having this kind of utility where we know we need to setup some type of fake case, but we want to hide it from the user, and it doesn't need to be fully functional like a real case.

``` python
diff --git a/scripts/lib/CIME/BuildTools/configure.py b/scripts/lib/CIME/BuildTools/configure.py
index a74c087a5..fd7067ed7 100644
--- a/scripts/lib/CIME/BuildTools/configure.py
+++ b/scripts/lib/CIME/BuildTools/configure.py
@@ -74,6 +74,9 @@ def get_value(self, attrib):
         expect(attrib in self._vals, "FakeCase does not support getting value of '%s'" % attrib)
         return self._vals[attrib]
 
+    def set_value(self, attrib, value):
+       self._vals[attrib] = value
+
 def _generate_env_mach_specific(output_dir, machobj, compiler, mpilib, debug,
                                 sysos, unit_testing):
     """
```

@jedwards4b does this sound acceptable? If so I'll submit a simple PR for it.
@billsacks would this kind of thing possibly make LILAC easier to setup?


Discussion:
Sure
Sounds good, Erik. Yes, I see the value for unit testing. It's hard to say whether it would help with LILAC... my gut sense is that you'd need to add a lot of functionality – or at least stubs – to the FakeCase before it could be used for something like LILAC or the other purposes you want to use it for, and I'm not sure whether it would be worth the effort to do so. But I haven't given it much thought, so could be wrong about that.
Sure
Sounds good, Erik. Yes, I see the value for unit testing. It's hard to say whether it would help with LILAC... my gut sense is that you'd need to add a lot of functionality – or at least stubs – to the FakeCase before it could be used for something like LILAC or the other purposes you want to use it for, and I'm not sure whether it would be worth the effort to do so. But I haven't given it much thought, so could be wrong about that.

Resolving patch:
diff --git a/CIME/BuildTools/configure.py b/CIME/BuildTools/configure.py
--- a/CIME/BuildTools/configure.py
+++ b/CIME/BuildTools/configure.py
@@ -153,6 +153,10 @@ def __init__(self, compiler, mpilib, debug, comp_interface, threading=False):
     def get_build_threaded(self):
         return self.get_value("SMP_PRESENT")
 
+    def get_case_root(self):
+        """Returns the root directory for this case."""
+        return self.get_value("CASEROOT")
+
     def get_value(self, attrib):
         expect(
             attrib in self._vals,
@@ -160,6 +164,10 @@ def get_value(self, attrib):
         )
         return self._vals[attrib]
 
+    def set_value(self, attrib, value):
+        """Sets a given variable value for the case"""
+        self._vals[attrib] = value
+
 
 def generate_env_mach_specific(
     output_dir,


Test patch: