示例#1
0
def test_delta_conf(mocker):
    source = TestAtomic()
    processor = TestAtomic()
    observer = TestAtomic()

    mocker.patch.object(source, 'ta', return_value=1.0)
    mocker.patch.object(source, 'output_func', return_value=(0, 1))
    mocker.patch.object(processor, 'ta', return_value=1.0)
    mocker.patch.object(processor, 'output_func', return_value=(0, 2))
    deltas = ['int', 'ext', 'conf']
    processor_delta_func = {
        delta: mocker.patch.object(processor, 'delta_{}'.format(delta))
        for delta in deltas
    }
    obs_delta_ext = mocker.patch.object(observer, 'delta_ext')

    digraph = devs.Digraph()
    digraph.add(source)
    digraph.add(processor)
    digraph.add(observer)
    digraph.couple(source, 0, processor, 0)
    digraph.couple(source, 0, observer, 0)
    digraph.couple(processor, 0, observer, 0)

    simulator = devs.Simulator(digraph)
    simulator.execute_next_event()

    assert not processor_delta_func['int'].called
    assert not processor_delta_func['ext'].called
    processor_delta_func['conf'].assert_called_once_with([(0, 1)])
    assert obs_delta_ext.call_count == 1
    assert obs_delta_ext.call_args[0][0] == 1.0
    assert len(obs_delta_ext.call_args[0][1]) == 2
    assert (0, 1) in obs_delta_ext.call_args[0][1]
    assert (0, 2) in obs_delta_ext.call_args[0][1]
示例#2
0
def test_simulator_exception_handled():
    source = Source()

    digraph = devs.Digraph()
    digraph.add(source)

    simulator = devs.Simulator(digraph)
    with pytest.raises(RuntimeError) as ex:
        simulator.execute_next_event()
    del simulator
    assert isinstance(ex.value, RuntimeError)
    exception_msg = str(ex.value)
    assert exception_msg.startswith("Python traceback follows:")
    assert "Intentional error in delta_int" in exception_msg
示例#3
0
def test_source_feeds_to_observer(mocker):
    source = TestAtomic()
    observer = TestAtomic()

    mocker.patch.object(source, 'ta', return_value=1.0)
    mocker.patch.object(source, 'output_func', return_value=(0, 1))
    obs_delta_ext = mocker.patch.object(observer, 'delta_ext')

    digraph = devs.Digraph()
    digraph.add(source)
    digraph.add(observer)
    digraph.couple(source, 0, observer, 0)

    simulator = devs.Simulator(digraph)
    simulator.execute_next_event()

    obs_delta_ext.assert_called_once_with(1.0, [(0, 1)])
示例#4
0
def digraph():
    return devs.Digraph()