1. Team SimPy
  2. Untitled project
  3. simpy

Commits

luensdorf  committed cee24c7

Created a new base environment class and moved step into this class. The default environment is derived from there and adds the peek and simulate methods.

  • Participants
  • Parent commits db914b9
  • Branches default

Comments (0)

Files changed (17)

File docs/examples/code/bank_renege.py

View file
 # Start processes and simulate
 counter = simpy.Resource(env, capacity=1)
 env.start(source(env, NEW_CUSTOMERS, INTERVAL_CUSTOMERS, counter))
-simpy.simulate(env)
+env.simulate()

File docs/examples/code/carwash.py

View file
 env.start(setup(env, NUM_MACHINES, WASHTIME, T_INTER))
 
 # Simulate!
-simpy.simulate(env, until=SIM_TIME)
+env.simulate(until=SIM_TIME)

File docs/examples/code/gas_station_refuel.py

View file
 env.start(car_generator(env, gas_station, fuel_pump))
 
 # Simulate!
-simpy.simulate(env, until=SIM_TIME)
+env.simulate(until=SIM_TIME)

File docs/examples/code/latency.py

View file
 env.start(sender(env, cable))
 env.start(receiver(env, cable))
 
-simpy.simulate(env, until=SIM_DURATION)
+env.simulate(until=SIM_DURATION)

File docs/examples/code/machine_shop.py

View file
 env.start(other_jobs(env, repairman))
 
 # Simulate!
-simpy.simulate(env, until=SIM_TIME)
+env.simulate(until=SIM_TIME)
 
 # Analyis/results
 print('Machine shop results after %s weeks' % WEEKS)

File docs/examples/code/movie_renege.py

View file
 
 # Start process and simulate
 env.start(customer_arrivals(env, theater))
-simpy.simulate(env, until=SIM_TIME)
+env.simulate(until=SIM_TIME)
 
 # Analysis/results
 for movie in movies:

File docs/examples/code/process_communication.py

View file
 env.start(message_consumer('Consumer A', env, pipe))
 
 print('\nOne-to-one pipe communication\n')
-simpy.simulate(env, until=SIM_TIME)
+env.simulate(until=SIM_TIME)
 
 # For one-to many use BroadcastPipe
 # (Note: could also be used for one-to-one,many-to-one or many-to-many)
 env.start(message_consumer('Consumer B', env, bc_pipe.get_output_conn()))
 
 print('\nOne-to-many pipe communication\n')
-simpy.simulate(env, until=SIM_TIME)
+env.simulate(until=SIM_TIME)

File simpy/__init__.py

View file
   :meth:`Environment.start()`. It inherits :class:`Event`.
 - :class:`Interrupt`: This exception is thrown into a process if it gets
   interrupted by another one.
-- :func:`peek()`: Return the next event's time.
-- :func:`step()`: Process the next event.
-- :func:`simulate()`: Execute the simulation until a given time.
 
 
 Resources
 .. - :func:`test`: Run the test suite on the installed copy of Simpy.
 
 """
-from simpy.core import Environment, Interrupt, Process, peek, step, simulate
+from simpy.core import Environment, Interrupt, Process
 from simpy.resources.resource import (
     Resource, PriorityResource, PreemptiveResource)
 from simpy.resources.container import Container
 
 __all__ = [
     'test',
-    'Environment', 'Interrupt', 'Process', 'peek', 'step', 'simulate',
+    'Environment', 'Interrupt', 'Process',
     'Resource', 'PriorityResource', 'PreemptiveResource',
     'Container',
     'Store', 'FilterStore',

File simpy/core.py

View file
             raise EmptySchedule()
 
 
-class Environment(object):
-    """The *environment* contains the simulation state and provides a
-    basic API for processes to interact with it.
+class BaseEnvironment(object):
+    """Base class for an environment, which schedules and executes events and
+    processes. 
 
     """
-    def __init__(self, initial_time=0, scheduler=None):
+    def __init__(self, scheduler):
+        self.scheduler = scheduler
         self._active_proc = None
 
-        if scheduler is None:
-            scheduler = Scheduler(self, initial_time)
-        self.scheduler = scheduler
-
-        self.event = types.MethodType(Event, self)
-        self.suspend = types.MethodType(Event, self)
-        self.timeout = types.MethodType(Timeout, self)
-        self.process = types.MethodType(Process, self)
-        self.start = types.MethodType(Process, self)
-
         self.schedule = self.scheduler.schedule
         self.pop = self.scheduler.pop
 
         """
         raise StopIteration(value)
 
+    def step(env):
+        """Get and process the next event for the Environment ``env``.
 
-def peek(env):
-    """Return the time of the Environment ``env``'s next event or
-    ``inf`` if the event queue is empty.
+        Raise an :exc:`IndexError` if no valid event is on the heap.
+
+        """
+        event = env.pop()
+
+        # Process callbacks of the event.
+        for callback in event.callbacks:
+            callback(event)
+        event.callbacks = None
+
+        if not event.ok:
+            # The event has failed, check if it is defused. Raise the value if not.
+            if not hasattr(event, 'defused'):
+                raise event._value
+
+
+class Environment(BaseEnvironment):
+    """The *environment* contains the simulation state and provides a
+    basic API for processes to interact with it.
 
     """
-    return env.scheduler.peek()
+    def __init__(self, initial_time=0, scheduler=None):
+        if scheduler is None:
+            scheduler = Scheduler(self, initial_time)
+        super(Environment, self).__init__(scheduler)
 
+        self.event = types.MethodType(Event, self)
+        self.suspend = types.MethodType(Event, self)
+        self.timeout = types.MethodType(Timeout, self)
+        self.process = types.MethodType(Process, self)
+        self.start = types.MethodType(Process, self)
 
-def step(env):
-    """Get and process the next event for the Environment ``env``.
+    def peek(self):
+        """Return the time at which the next event is scheduled or ``inf`` if
+        the event queue is empty.
 
-    Raise an :exc:`IndexError` if no valid event is on the heap.
+        """
+        return self.scheduler.peek()
 
-    """
-    event = env.pop()
+    def simulate(self, until=None):
+        """Executes events until the given criterion *until* is met.
 
-    # Process callbacks of the event.
-    for callback in event.callbacks:
-        callback(event)
-    event.callbacks = None
+        - If it is ``None`` (which is the default) the execution will only
+          stop if there are no further events.
 
-    if not event.ok:
-        # The event has failed, check if it is defused. Raise the value if not.
-        if not hasattr(event, 'defused'):
-            raise event._value
+        - If it is an :class:`Event` the execution will stop once this
+          event has been triggered.
 
+        - If it can be converted to a number the execution will stop when the
+          simulation time reaches *until*. (*Note:* Internally, an event is
+          created, so the simulation time will be exactly *until* afterwards.
+          No other events scheduled for *until* will be processed, though---as
+          it is at the very beginning of the simulation.)
 
-def simulate(env, until=None):
-    """Simulate the environment until the given criterion *until* is met.
+        """
+        if until is None:
+            until = Event(self)
+        elif not isinstance(until, Event):
+            at = float(until)
 
-    The parameter ``until`` specifies when the simulation ends.
+            if at <= self.now:
+                raise ValueError('until(=%s) should be > the current '
+                        'simulation time.' % at)
 
-    - If it is ``None`` (which is the default) the simulation will only
-      stop if there are no further events.
+            # Schedule the event with before all regular timeouts.
+            until = Event(self)
+            until._value = None
+            self.schedule(until, HIGH_PRIORITY, at - self.now)
 
-    - If it is an :class:`Event` the simulation will stop once this
-      event has happened.
+        until.callbacks.append(_stop_simulate)
 
-    - If it can be converted to a number the simulation will stop when the
-      simulation time reaches *until*. (*Note:* Internally, an event is
-      created, so the simulation time will be exactly *until* afterwards. No
-      other events scheduled for *until* will be processed, though---as it is
-      at the very beginning of the simulation.)
+        try:
+            while True:
+                self.step()
+        except EmptySchedule:
+            pass
 
-    """
-    if until is None:
-        until = env.event()
-    elif not isinstance(until, Event):
-        at = float(until)
-
-        if at <= env.now:
-            raise ValueError('until(=%s) should be > the current simulation '
-                             'time.' % at)
-
-        # Schedule the event with before all regular timeouts.
-        until = env.event()
-        until._value = None
-        env.schedule(until, HIGH_PRIORITY, at - env.now)
-
-    until.callbacks.append(_stop_simulate)
-
-    try:
-        while True:
-            step(env)
-    except EmptySchedule:
-        pass
-
-    return until.value if until.triggered else None
+        return until.value if until.triggered else None
 
 
 def _describe_frame(frame):

File simpy/test/test_condition.py

View file
 import pytest
 
-from simpy import simulate
-
 
 def test_operator_and(env):
     def process(env):
         }
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_operator_or(env):
         }
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_operator_nested_and(env):
         assert env.now == 1
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_operator_nested_or(env):
         assert env.now == 2
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_nested_cond_with_error(env):
             assert err.args == ('Onoes!',)
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_cond_with_error(env):
             assert err.args == ('Onoes, failed after 0!',)
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_cond_with_nested_error(env):
             assert err.args == ('Onoes, failed after 0!',)
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_cond_with_uncaught_error(env):
 
     env.start(process(env))
     try:
-        simulate(env)
+        env.simulate()
         assert False, 'There should have been an exception.'
     except ValueError:
         pass
         assert sorted(results.values()) == [0, 1, 2]
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_iand_with_or_cond(env):
         assert sorted(results.values()) == [0, 1]
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_ior_with_or_cond(env):
         assert sorted(results.values()) == [0]
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_ior_with_and_cond(env):
         assert sorted(results.values()) == [0]
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_immutable_results(env):
         assert results == {timeout[0]: 0}
 
     env.start(process(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_shared_and_condition(env):
 
     env.start(p1(env, c1))
     env.start(p2(env, c2))
-    simulate(env)
+    env.simulate()
 
 
 def test_shared_or_condition(env):
 
     env.start(p1(env, c1))
     env.start(p2(env, c2))
-    simulate(env)
+    env.simulate()

File simpy/test/test_exceptions.py

View file
             assert err.args[0] == 'Onoes!'
 
     env.start(parent(env))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_no_parent_process(env):
             pytest.fail('There should be no error (%s).' % err)
 
     env.start(parent(env))
-    pytest.raises(ValueError, simpy.simulate, env)
+    pytest.raises(ValueError, env.simulate)
 
 
 def test_crashing_child_traceback(env):
             assert 'raise RuntimeError(\'Oh noes,' in stacktrace
 
     env.start(root(env))
-    simpy.simulate(env)
+    env.simulate()
 
 
 @pytest.mark.skipif('sys.version_info[0] < 3')
 
     env.start(grandparent(env))
     try:
-        simpy.simulate(env)
+        env.simulate()
         pytest.fail('There should have been an exception')
     except RuntimeError:
         import traceback
 
     env.start(root(env))
     try:
-        simpy.simulate(env)
+        env.simulate()
         pytest.fail('Hey, this is not allowed!')
     except RuntimeError as err:
         assert err.args[0].endswith('Invalid yield value "None"')
     event = env.event()
     event.fail(RuntimeError())
     try:
-        simpy.simulate(env, until=1)
+        env.simulate(until=1)
         assert False, 'There must be a RuntimeError!'
     except RuntimeError:
         pass
     event.callbacks.append(callback)
     event.fail(RuntimeError())
     assert not hasattr(event, 'defused'), 'Event has been defused immediately'
-    simpy.simulate(env, until=1)
+    env.simulate(until=1)
     assert event.defused, 'Event has not been defused'
 
 
     event.fail(RuntimeError())
 
     assert not hasattr(event, 'defused'), 'Event has been defuseed immediately'
-    simpy.simulate(env, until=1)
+    env.simulate(until=1)
     assert event.defused, 'Event has not been defused'

File simpy/test/test_interrupts.py

View file
         child_process.interrupt('interrupt!')
 
     env.start(interruptor(env))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_concurrent_interrupts(env, log):
     for name in ('boggis', 'bunce', 'beans'):
         env.start(farmer(env, name, fantastic_mr_fox))
 
-    simpy.simulate(env, 20)
+    env.simulate(20)
     assert log == [(0, 'boggis'), (0, 'bunce'), (0, 'beans')]
 
 
         yield env.timeout(1)
 
     env.start(root(env))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_interrupt_terminated_process(env):
         yield env.timeout(1)
 
     env.start(parent(env))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_multiple_interrupts(env):
         assert result == 1
 
     env.start(parent(env))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_interrupt_self(env):
         yield env.timeout(0)
 
     env.start(pem(env))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_immediate_interrupt(env, log):
 
     c = env.start(child(env, log))
     env.start(resumer(env, c))
-    simpy.simulate(env)
+    env.simulate()
 
     # Confirm that child has been interrupted immediately at timestep 0.
     assert log == [0]
         child_proc.interrupt()
 
     env.start(parent(env))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_interrupt_event(env):
         child_proc.interrupt()
 
     env.start(parent(env))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_concurrent_behaviour(env):
     proc_a = env.start(proc_a(env))
     env.start(proc_b(env, proc_a))
 
-    simpy.simulate(env)
+    env.simulate()

File simpy/test/test_resources.py

View file
     assert resource.count == 0
     env.start(pem(env, 'a', resource, log))
     env.start(pem(env, 'b', resource, log))
-    simpy.simulate(env)
+    env.simulate()
 
     assert log == [('a', 1), ('b',  2)]
 
     resource = simpy.Resource(env, capacity=1)
     env.start(pem(env, 'a', resource, log))
     env.start(pem(env, 'b', resource, log))
-    simpy.simulate(env)
+    env.simulate()
 
     assert log == [('a', 1), ('b',  2)]
 
     resource = simpy.Resource(env, capacity=3)
     for i in range(9):
         env.start(pem(env, str(i), resource, log))
-    simpy.simulate(env)
+    env.simulate()
 
     assert log == [('0', 0), ('1', 0), ('2', 0),
             ('3', 1), ('4', 1), ('5', 1),
     env.start(pem(env, res))
     proc = env.start(victim(env, res))
     env.start(interruptor(env, proc))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_resource_release_after_interrupt(env):
     env.start(blocker(env, res))
     victim_proc = env.start(victim(env, res))
     env.start(interruptor(env, victim_proc))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_resource_cm_exception(env, log):
     # The second process is used to check if it was able to access the
     # resource:
     env.start(process(env, resource, log, False))
-    simpy.simulate(env)
+    env.simulate()
 
     assert log == [1, 2]
 
 
     resource = simpy.Resource(env, 1)
     env.start(process(env, resource))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_resource_with_priority_queue(env):
     env.start(process(env, 2, resource, 3, 10))
     env.start(process(env, 2, resource, 3, 15))  # Test equal priority
     env.start(process(env, 4, resource, 1, 5))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_get_users(env):
 
     resource = simpy.Resource(env, 1)
     procs = [env.start(process(env, resource)) for i in range(3)]
-    simpy.simulate(env, until=1)
+    env.simulate(until=1)
     assert [evt.proc for evt in resource.users] == procs[0:1]
     assert [evt.proc for evt in resource.queue] == procs[1:]
 
-    simpy.simulate(env, until=2)
+    env.simulate(until=2)
     assert [evt.proc for evt in resource.users] == procs[1:2]
     assert [evt.proc for evt in resource.queue] == procs[2:]
 
     p2 = env.start(process(2, env, res, 1, 0, log))
     p3 = env.start(process(3, env, res, 2, 2, log))
 
-    simpy.simulate(env)
+    env.simulate()
 
     assert log == [(1, 1, (p2, 0)), (5, 0), (6, 2), (10, 3)]
 
     env.start(proc_a(env, resource, 1))
     env.start(proc_b(env, resource, 0))
 
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_mixed_preemption(env, log):
     p3 = env.start(process(3, env, res, 1, 0, True, log))
     p4 = env.start(process(4, env, res, 2, 2, True, log))
 
-    simpy.simulate(env)
+    env.simulate()
 
     assert log == [
         (1, 1, (p3, 0)),
     buf = simpy.Container(env, init=0, capacity=2)
     env.start(putter(env, buf, log))
     env.start(getter(env, buf, log))
-    simpy.simulate(env, until=5)
+    env.simulate(until=5)
 
     assert log == [('p', 1), ('g', 1), ('g', 2), ('p', 2)]
 
     p2 = env.start(proc(env, 1, container, 'put'))
     p3 = env.start(proc(env, 1, container, 'put'))
 
-    simpy.simulate(env, until=1)
+    env.simulate(until=1)
     assert [ev.proc for ev in container.put_queue] == []
     assert [ev.proc for ev in container.get_queue] == [p0]
 
-    simpy.simulate(env, until=2)
+    env.simulate(until=2)
     assert [ev.proc for ev in container.put_queue] == [p3]
     assert [ev.proc for ev in container.get_queue] == []
 
     # NOTE: Does the start order matter? Need to test this.
     env.start(putter(env, store, item))
     env.start(getter(env, store, item))
-    simpy.simulate(env)
+    env.simulate()
 
 
 def test_store_capacity(env):
         assert get_event.triggered
 
     env.start(pem(env))
-    simpy.simulate(env)
+    env.simulate()

File simpy/test/test_rt.py

View file
 
 import pytest
 
-from simpy import simulate
 from simpy.rt import RealtimeEnvironment
 
 
     env.start(process(env, log, 0.02, 1))
 
     start = perf_counter()
-    simulate(env, 2)
+    env.simulate(2)
     duration = perf_counter() - start
 
     assert check_duration(duration, 2 * factor)
     env.start(process(env, log, 0.01, 2))
     env.start(process(env, log, 0.01, 3))
 
-    simulate(env, 5)
+    env.simulate(5)
     duration = perf_counter() - start
 
     # assert almost_equal(duration, 0.2)
     assert check_duration(duration, 5 * 0.05)
     assert log == [2, 3, 4]
 
-    simulate(env, 12)
+    env.simulate(12)
     duration = perf_counter() - start
 
     assert check_duration(duration, 12 * 0.05)
     env = RealtimeEnvironment(factor=0.05)
     env.start(process(env, log, 0.1, 1))
 
-    err = pytest.raises(RuntimeError, simulate, env, 3)
+    err = pytest.raises(RuntimeError, env.simulate, 3)
     assert 'Simulation too slow for real time (0.05' in err.value.args[0]
     assert log == []
 
     env.start(process(env, log, 0.1, 1))
 
     start = perf_counter()
-    simulate(env, 2)
+    env.simulate(2)
     duration = perf_counter() - start
 
     assert check_duration(duration, 2 * 0.1)
 def test_rt_illegal_until():
     """Test illegal value for *until*."""
     env = RealtimeEnvironment()
-    err = pytest.raises(ValueError, simulate, env, -1)
+    err = pytest.raises(ValueError, env.simulate, -1)
     assert err.value.args[0] == ('until(=-1.0) should be > the current '
             'simulation time.')

File simpy/test/test_single_process.py

View file
 
 import pytest
 
-from simpy import Process, simulate, peek, step
+from simpy import Process
 
 
 def test_discrete_time_steps(env, log):
             yield env.timeout(delay=1)
 
     env.start(pem(env, log))
-    simulate(env, until=3)
+    env.simulate(until=3)
 
     assert log == [0, 1, 2]
 
             yield env.timeout(1)
 
     env.start(pem(env, log))
-    simulate(env, 10)
+    env.simulate(10)
 
     assert log == [0, 1]
 
         yield env.timeout(-1)
 
     env.start(pem(env))
-    pytest.raises(ValueError, simulate, env)
+    pytest.raises(ValueError, env.simulate)
 
 
 def test_get_process_state(env):
 
     proc_a = env.start(pem_a(env))
     env.start(pem_b(env, proc_a))
-    simulate(env)
+    env.simulate()
 
 
 def test_simulate_negative_until(env):
     """Test passing a negative time to simulate."""
-    pytest.raises(ValueError, simulate, env, -3)
+    pytest.raises(ValueError, env.simulate, -3)
 
 
 def test_timeout_value(env):
         assert val == 'ohai'
 
     env.start(pem(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_event_succeeds(env):
         event.succeed('ohai')
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_event_fails(env):
         event.fail(ValueError('ohai'))
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_exit_with_process(env):
         assert type(result) is Process
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_shared_timeout(env, log):
     for i in range(3):
         env.start(child(env, timeout, i, log))
 
-    simulate(env)
+    env.simulate()
     assert log == [(0, 1), (1, 1), (2, 1)]
 
 
     proc = env.start(pem(env, event))
 
     # Wait until "proc" is initialized and yielded the event
-    while peek(env) < 5:
-        step(env)
+    while env.peek() < 5:
+        env.step()
     assert proc.target is event
     proc.interrupt()
 
     """Stopped simulation can be resumed."""
     events = [env.timeout(t) for t in (5, 10, 15)]
 
-    simulate(env, until=10)
+    env.simulate(until=10)
     assert events[0].processed
     assert not events[1].processed
     assert not events[2].processed
     assert env.now == 10
 
-    simulate(env, until=15)
+    env.simulate(until=15)
     assert events[1].processed
     assert not events[2].processed
     assert env.now == 15
 
-    simulate(env)
+    env.simulate()
     assert events[2].processed
     assert env.now == 15
 
 
 def test_simulate_until_value(env):
     """Anything that can be converted to a float is a valid until value."""
-    simulate(env, until='3.141592')
+    env.simulate(until='3.141592')
     assert env.now == 3.141592
 
 
     """After an event has been triggered, its value becomes accessible."""
     event = env.timeout(0, 'I am the value')
 
-    simulate(env)
+    env.simulate()
 
     assert event.value == 'I am the value'
 
     event = env.event()
     event.succeed('i was already done')
 
-    result = simulate(env, env.start(pem(env, event)))
+    result = env.simulate(env.start(pem(env, event)))
 
     assert result == 'i was already done'
 

File simpy/test/test_util.py

View file
 
 import pytest
 
-from simpy import Interrupt, simulate
+from simpy import Interrupt
 from simpy.util import start_delayed, subscribe_at, all_of, any_of
 
 
         yield env.timeout(1)
 
     start_delayed(env, pem(env), delay=5)
-    simulate(env)
+    env.simulate()
 
 
 def test_start_delayed_error(env):
             assert env.now == 3
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_subscribe_terminated_proc(env):
         pytest.raises(RuntimeError, subscribe_at, child_proc)
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_subscribe_with_join(env):
             assert child_proc2.is_alive
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_subscribe_at_timeout(env):
             assert env.now == 2
 
     env.start(pem(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_subscribe_at_timeout_with_value(env):
             assert env.now == 2
 
     env.start(pem(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_all_of(env):
         assert env.now == 9
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_wait_for_all_with_errors(env):
         assert events[2] not in condition._interim_values
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_all_of_chaining(env):
         assert sorted(results.values()) == [0, 0, 1, 1]
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_all_of_chaining_intermediate_results(env):
         assert sorted(results.values()) == [0, 0, 1, 1]
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_all_of_with_triggered_events(env):
                             r'been triggered', e.args[0])
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_any_of(env):
         assert env.now == 0
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_any_of_with_errors(env):
         assert events[1] not in condition._interim_values
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_any_of_chaining(env):
         assert sorted(results.values()) == ['b']
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_any_of_with_triggered_events(env):
                             r'been triggered', e.args[0])
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()

File simpy/test/test_wait_for_proc.py

View file
 """
 import pytest
 
-from simpy import Interrupt, simulate
+from simpy import Interrupt
 
 
 def test_wait_for_proc(env):
         assert env.now == 5
 
     env.start(waiter(env, finisher))
-    simulate(env)
+    env.simulate()
 
 
 def test_exit(env):
         assert [result1, result2] == [1, 2]
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 @pytest.mark.skipif('sys.version_info[:2] < (3, 3)')
         assert [result1, result2] == [1, 2]
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_child_exception(env):
         assert isinstance(result, Exception)
 
     env.start(parent(env))
-    simulate(env)
+    env.simulate()
 
 
 def test_interrupted_join(env):
 
     parent_proc = env.start(parent(env))
     env.start(interruptor(env, parent_proc))
-    simulate(env)
+    env.simulate()
 
 
 def test_interrupted_join_and_rejoin(env):
 
     parent_proc = env.start(parent(env))
     env.start(interruptor(env, parent_proc))
-    simulate(env)
+    env.simulate()
 
 
 def test_unregister_after_interrupt(env):
 
     parent_proc = env.start(parent(env))
     env.start(interruptor(env, parent_proc))
-    simulate(env)
+    env.simulate()
 
 
 def test_error_and_interrupted_join(env):
         yield env.timeout(0)
 
     env.start(parent(env))
-    pytest.raises(AttributeError, simulate, env)
+    pytest.raises(AttributeError, env.simulate)