From f1134a91c7e89c6b2961439ff71290ddb9dbc26a Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Mon, 23 Nov 2020 20:18:32 -0500 Subject: [PATCH] #1230 coverage --- pybamm/expression_tree/input_parameter.py | 1 + pybamm/solvers/base_solver.py | 23 ++++++++----------- .../test_input_parameter.py | 2 ++ .../test_operations/test_jac.py | 2 +- tests/unit/test_timer.py | 1 + 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pybamm/expression_tree/input_parameter.py b/pybamm/expression_tree/input_parameter.py index d27c1f6a25..78357beb11 100644 --- a/pybamm/expression_tree/input_parameter.py +++ b/pybamm/expression_tree/input_parameter.py @@ -39,6 +39,7 @@ def set_expected_size(self, size): # We also need to update the saved size and shape self._saved_size = size self._saved_shape = (size, 1) + self._saved_evaluate_for_shape = self._evaluate_for_shape() def _evaluate_for_shape(self): """ diff --git a/pybamm/solvers/base_solver.py b/pybamm/solvers/base_solver.py index 837e801fe3..ab4761c9b3 100644 --- a/pybamm/solvers/base_solver.py +++ b/pybamm/solvers/base_solver.py @@ -841,20 +841,17 @@ def step( termination = self.get_termination_reason(solution, model.events) pybamm.logger.debug("Finish stepping {} ({})".format(model.name, termination)) - if set_up_time: - pybamm.logger.debug( - ( - "Set-up time: {}, Step time: {} (of which integration time: {}), " - "Total time: {}" - ).format( - solution.set_up_time, - solution.solve_time, - solution.integration_time, - solution.total_time, - ) + pybamm.logger.debug( + ( + "Set-up time: {}, Step time: {} (of which integration time: {}), " + "Total time: {}" + ).format( + solution.set_up_time, + solution.solve_time, + solution.integration_time, + solution.total_time, ) - else: - pybamm.logger.debug("Step time: {}".format(solution.solve_time)) + ) if save is False or old_solution is None: return solution else: diff --git a/tests/unit/test_expression_tree/test_input_parameter.py b/tests/unit/test_expression_tree/test_input_parameter.py index 462d0ae7ff..2a976fd17c 100644 --- a/tests/unit/test_expression_tree/test_input_parameter.py +++ b/tests/unit/test_expression_tree/test_input_parameter.py @@ -36,6 +36,8 @@ def test_evaluate_for_shape(self): a.set_expected_size(10) self.assertEqual(a.shape, (10, 1)) + np.testing.assert_equal(a.evaluate_for_shape(), np.nan * np.ones((10, 1))) + self.assertEqual(a.evaluate_for_shape().shape, (10, 1)) def test_errors(self): a = pybamm.InputParameter("a") diff --git a/tests/unit/test_expression_tree/test_operations/test_jac.py b/tests/unit/test_expression_tree/test_operations/test_jac.py index 679357b3a7..83851d592f 100644 --- a/tests/unit/test_expression_tree/test_operations/test_jac.py +++ b/tests/unit/test_expression_tree/test_operations/test_jac.py @@ -213,7 +213,7 @@ def test_functions(self): np.testing.assert_array_equal(jacobian, dfunc_dy.toarray()) # when child evaluates to number - func = pybamm.sin(const) + func = pybamm.Sin(const) dfunc_dy = func.jac(y).evaluate(y=y0) np.testing.assert_array_equal(0, dfunc_dy) diff --git a/tests/unit/test_timer.py b/tests/unit/test_timer.py index 9b63f91f54..0fb48dbee4 100644 --- a/tests/unit/test_timer.py +++ b/tests/unit/test_timer.py @@ -60,6 +60,7 @@ def test_timer_operations(self): self.assertEqual((pybamm.TimerTime(1) - pybamm.TimerTime(2)).value, -1) self.assertEqual((1 - pybamm.TimerTime(1)).value, 0) self.assertEqual((pybamm.TimerTime(4) * 2).value, 8) + self.assertEqual((pybamm.TimerTime(4) * pybamm.TimerTime(2)).value, 8) self.assertEqual((2 * pybamm.TimerTime(5)).value, 10) self.assertEqual((pybamm.TimerTime(4) / 2).value, 2) self.assertEqual((pybamm.TimerTime(4) / pybamm.TimerTime(2)).value, 2)