From e103579ccda093e1ebec5e59872c258d39de47d0 Mon Sep 17 00:00:00 2001 From: Arthur Goldberg Date: Sun, 27 Dec 2020 14:40:32 -0500 Subject: [PATCH] represent time in DynamicMultialgorithmErrors in scientific notation --- tests/test_multialgorithm_errors.py | 3 ++- wc_sim/multialgorithm_errors.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_multialgorithm_errors.py b/tests/test_multialgorithm_errors.py index 9caafe9e..3fc9f471 100644 --- a/tests/test_multialgorithm_errors.py +++ b/tests/test_multialgorithm_errors.py @@ -6,6 +6,7 @@ """ import os +import re import unittest from wc_sim.multialgorithm_errors import (DynamicFrozenSimulationError, DynamicMultialgorithmError, @@ -28,7 +29,7 @@ def test_errors(self): raise SpeciesPopulationError(msg) def expected(time, msg): - return f"{time}: {msg}" + return re.escape(f"{time:.{DynamicMultialgorithmError.TIME_PRECISION}E}: {msg}") time = 3.5 with self.assertRaisesRegexp(DynamicFrozenSimulationError, expected(time, msg)): diff --git a/wc_sim/multialgorithm_errors.py b/wc_sim/multialgorithm_errors.py index 0a2dc43e..07301d48 100644 --- a/wc_sim/multialgorithm_errors.py +++ b/wc_sim/multialgorithm_errors.py @@ -36,10 +36,11 @@ class DynamicMultialgorithmError(Error): time (:obj:`float`): the simulation time at which the error occurs message (:obj:`str`): the exception's message """ + TIME_PRECISION = 5 def __init__(self, time, message=None): self.time = time - super().__init__(f"{time}: {message}") + super().__init__(f"{time:.{self.TIME_PRECISION}E}: {message}") class SpeciesPopulationError(Error):