Ejemplo n.º 1
0
def test_SimulationContext_finalize(base_config, components):
    sim = SimulationContext(base_config, components)
    listener = [c for c in components if 'listener' in c.args][0]
    sim.setup()
    sim.initialize_simulants()
    sim.step()
    assert not listener.simulation_end_called
    sim.finalize()
    assert listener.simulation_end_called
Ejemplo n.º 2
0
def test_SimulationContext_step(log, base_config, components):
    sim = SimulationContext(base_config, components)
    sim.setup()

    current_time = sim.clock.time
    step_size = sim.clock.step_size

    listener = [c for c in components if 'listener' in c.args][0]

    assert not listener.time_step__prepare_called
    assert not listener.time_step_called
    assert not listener.time_step__cleanup_called
    assert not listener.collect_metrics_called

    sim.step()

    assert log.debug.called_once_with(current_time)
    assert listener.time_step__prepare_called
    assert listener.time_step_called
    assert listener.time_step__cleanup_called
    assert listener.collect_metrics_called

    assert sim.clock.time == current_time + step_size