Repository: ModellingWebLab/cellmlmanip

Issue:
Initial values aren't copied in unit conversion
If they're 0

Discussion:

Patch:
diff --git a/cellmlmanip/model.py b/cellmlmanip/model.py
index d0882a0..90b458b 100644
--- a/cellmlmanip/model.py
+++ b/cellmlmanip/model.py
@@ -968,7 +968,7 @@ class Model(object):
 
         # If original has initial_value calculate new initial value (only needed for INPUT case)
         new_value = None
-        if direction == DataDirectionFlow.INPUT and original_variable.initial_value:
+        if direction == DataDirectionFlow.INPUT and original_variable.initial_value is not None:
             new_value = original_variable.initial_value * cf
 
         # Create new variable


Test patch:
diff --git a/tests/test_unit_conversion.py b/tests/test_unit_conversion.py
index 1a8867c..23b9867 100644
--- a/tests/test_unit_conversion.py
+++ b/tests/test_unit_conversion.py
@@ -213,6 +213,21 @@ class TestUnitConversion:
         assert len(states) == 1
         assert symbol_a in states
 
+    def test_add_input_state_variable_initial_zero(self, local_model):
+        """
+        Same as :meth:`test_add_input_state_variable`, but for the special case where the initial value of the state
+        variable is 0.
+        """
+        assert self._original_state_local_model(local_model)
+
+        # change mV to V
+        original_var = local_model.get_variable_by_cmeta_id('sv11')
+        original_var.initial_value = 0
+        volt_unit = local_model.units.get_unit('volt')
+        newvar = local_model.convert_variable(original_var, volt_unit, DataDirectionFlow.INPUT)
+        assert newvar != original_var
+        assert newvar.initial_value == 0
+
     def test_add_input_free_variable(self, local_model):
         """ Tests the Model.convert_variable function that changes units of given variable.
         This particular case tests changing a free variable