Repository: pybamm-team/PyBaMM

Issue:
Running thermal_lithium_ion example doesn't find parameters
**Describe the bug**
FileNotFoundError: [Errno 2] File b'C:\\Code\\PyBaMM\\examples\\scripts\\input\\parameters\\lithium-ion\\mcmb2528_lif6-in-ecdmc_lico2_parameters_Dualfoil.csv' does not exist: b'C:\\Code\\PyBaMM\\examples\\scripts\\input\\parameters\\lithium-ion\\mcmb2528_lif6-in-ecdmc_lico2_parameters_Dualfoil.csv'

**To Reproduce**
Steps to reproduce the behaviour:
check out master
run example

I think it needs these lines added like the other examples
import os
os.chdir(pybamm.__path__[0]+'/..')
or perhaps the base_battery_model should try to find a file in cwd and if not found go to the root


Discussion:

Patch:
diff --git a/pybamm/models/full_battery_models/base_battery_model.py b/pybamm/models/full_battery_models/base_battery_model.py
index 798d67f48..8851bada0 100644
--- a/pybamm/models/full_battery_models/base_battery_model.py
+++ b/pybamm/models/full_battery_models/base_battery_model.py
@@ -24,7 +24,10 @@ class BaseBatteryModel(pybamm.BaseModel):
     def default_parameter_values(self):
         # Default parameter values, geometry, submesh, spatial methods and solver
         # Lion parameters left as default parameter set for tests
-        input_path = os.path.join(os.getcwd(), "input", "parameters", "lithium-ion")
+        input_path = os.path.join(
+            pybamm.root_dir(),
+            "input", "parameters", "lithium-ion"
+        )
         return pybamm.ParameterValues(
             os.path.join(
                 input_path, "mcmb2528_lif6-in-ecdmc_lico2_parameters_Dualfoil.csv"
@@ -32,7 +35,7 @@ class BaseBatteryModel(pybamm.BaseModel):
             {
                 "Typical current [A]": 1,
                 "Current function": os.path.join(
-                    os.getcwd(),
+                    pybamm.root_dir(),
                     "pybamm",
                     "parameters",
                     "standard_current_functions",
@@ -373,4 +376,3 @@ class BaseBatteryModel(pybamm.BaseModel):
         # Cut-off voltage
         voltage = self.variables["Terminal voltage"]
         self.events["Minimum voltage"] = voltage - self.param.voltage_low_cut
-
diff --git a/pybamm/models/full_battery_models/lead_acid/base_lead_acid_model.py b/pybamm/models/full_battery_models/lead_acid/base_lead_acid_model.py
index b1a0e24a3..4e3680f08 100644
--- a/pybamm/models/full_battery_models/lead_acid/base_lead_acid_model.py
+++ b/pybamm/models/full_battery_models/lead_acid/base_lead_acid_model.py
@@ -22,13 +22,13 @@ class BaseModel(pybamm.BaseBatteryModel):
 
     @property
     def default_parameter_values(self):
-        input_path = os.path.join(os.getcwd(), "input", "parameters", "lead-acid")
+        input_path = os.path.join(pybamm.root_dir(), "input", "parameters", "lead-acid")
         return pybamm.ParameterValues(
             "input/parameters/lead-acid/default.csv",
             {
                 "Typical current [A]": 1,
                 "Current function": os.path.join(
-                    os.getcwd(),
+                    pybamm.root_dir(),
                     "pybamm",
                     "parameters",
                     "standard_current_functions",


Test patch:
diff --git a/tests/unit/test_models/test_base_model.py b/tests/unit/test_models/test_base_model.py
index 8f640960f..597f67e75 100644
--- a/tests/unit/test_models/test_base_model.py
+++ b/tests/unit/test_models/test_base_model.py
@@ -2,7 +2,6 @@
 # Tests for the base model class
 #
 import pybamm
-
 import unittest
 
 
@@ -329,7 +328,10 @@ class TestBaseModel(unittest.TestCase):
         }
 
         # Check warning raised
-        self.assertWarns(pybamm.ModelWarning, model.check_well_posedness())
+        # TODO: getting a strange bug here, related to CPython bug here:
+        #    https://bugs.python.org/issue29620
+        # with self.assertWarns(pybamm.ModelWarning):
+        model.check_well_posedness()
 
         # Check None entries have been removed from the variables dictionary
         for key, item in model._variables.items():
@@ -371,6 +373,21 @@ class TestStandardBatteryBaseModel(unittest.TestCase):
         )
         self.assertIsInstance(solver, pybamm.BaseModel)
 
+    def test_default_parameters(self):
+        # check parameters are read in ok
+        model = pybamm.BaseBatteryModel()
+        self.assertEqual(
+            model.default_parameter_values['Reference temperature [K]'], 298.15)
+
+        # change path and try again
+        import os
+        cwd = os.getcwd()
+        os.chdir('..')
+        model = pybamm.BaseBatteryModel()
+        self.assertEqual(
+            model.default_parameter_values['Reference temperature [K]'], 298.15)
+        os.chdir(cwd)
+
 
 if __name__ == "__main__":
     print("Add -v for more debug output")