Skip to content

Commit

Permalink
represent time in DynamicMultialgorithmErrors in scientific notation
Browse files Browse the repository at this point in the history
  • Loading branch information
artgoldberg committed Dec 27, 2020
1 parent 44778df commit e103579
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tests/test_multialgorithm_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import os
import re
import unittest

from wc_sim.multialgorithm_errors import (DynamicFrozenSimulationError, DynamicMultialgorithmError,
Expand All @@ -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)):
Expand Down
3 changes: 2 additions & 1 deletion wc_sim/multialgorithm_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e103579

Please sign in to comment.