1. Team SimPy
  2. Untitled project
  3. simpy

Commits

Stefan Scherfke  committed 26bfe62

Fixed real-time test.

  • Participants
  • Parent commits 847bcda
  • Branches default

Comments (0)

Files changed (2)

File simpy/rt.py

View file
 Helpers for real-time (aka *wallclock time*) simulations.
 
 """
-from numbers import Number
 try:
     # Python >= 3.3
     from time import monotonic as time, sleep
     # Python < 3.3
     from time import time, sleep
 
-from simpy.core import Environment, Scheduler, simulate
+from simpy.core import Environment, Scheduler
 
 
 Infinity = float('inf')
             # Events scheduled for time *t* may take just up to *t+1*
             # for their computation, before an error is raised.
             raise RuntimeError(
-                    'Simulation too slow for real time (%.3fs).' % -delay)
+                'Simulation too slow for real time (%.3fs).' % -delay)
         return event
 
 
     A simulation time step in this environment will take *factor* seconds of
     real time (one second by default), e.g. if you simulate from ``0`` until
     ``3`` with ``factor=0.5``, the call will take at least 1.5 seconds. If the
-    processing of the events for a time step takes to long, a
+    processing of the events for a time step takes too long, a
     :exc:`RuntimeError` is raised. You can disable this behavior by setting
     *strict* to ``False``.
     """
 
     def __init__(self, initial_time=0, factor=1.0, strict=True):
-        Environment.__init__(self, initial_time,
-                RealtimeScheduler(self, initial_time, factor, strict))
+        Environment.__init__(self, initial_time, RealtimeScheduler(
+            self, initial_time, factor, strict))

File simpy/test/test_rt.py

View file
 
 import pytest
 
-from simpy.rt import RealtimeEnvironment, simulate
+from simpy import simulate
+from simpy.rt import RealtimeEnvironment
 
 
 def process(env, log, sleep, timeout=1):
 def test_rt_multiple_call(log):
     """Test multiple calls to simulate()."""
     env = RealtimeEnvironment(factor=0.05)
+    start = perf_counter()
+
     env.start(process(env, log, 0.01, 2))
     env.start(process(env, log, 0.01, 3))
 
-    start = perf_counter()
     simulate(env, 5)
     duration = perf_counter() - start
 
     assert check_duration(duration, 5 * 0.05)
     assert log == [2, 3, 4]
 
-    start = perf_counter()
     simulate(env, 12)
     duration = perf_counter() - start
 
-    assert check_duration(duration, 7 * 0.05)
+    assert check_duration(duration, 12 * 0.05)
     assert log == [2, 3, 4, 6, 6, 8, 9, 10]