Exemplo n.º 1
0
def test_two_events():
    foo = PortEvent(port='air_port')
    bar = PortEvent(port='earth_port')

    with EventManager(((foo, 1.), (bar, 1.2))) as mngr:
        assert_port_value_equal(foo._port, 'air__density', 0.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)

        mngr.run(1.)
        assert_port_value_equal(foo._port, 'air__density', 1.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)

        mngr.run(1.)
        assert_port_value_equal(foo._port, 'air__density', 1.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)

        mngr.run(1.3)
        assert_port_value_equal(foo._port, 'air__density', 1.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 1.2)

        mngr.run(2.)
        assert_port_value_equal(foo._port, 'air__density', 2.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 1.2)

        for time in np.arange(2., 5., .1):
            mngr.run(time)
        assert_almost_equal(mngr.time, 4.9)
        assert_port_value_equal(foo._port, 'air__density', 4.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 4.8)

    assert_port_value_equal(foo._port, 'air__density', 0.)
    assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)
Exemplo n.º 2
0
def test_chain():
    air = get_component_instance('air_port')
    earth = get_component_instance('earth_port')

    foo = ChainEvent([
        PortEvent(port=air),
        PortMapEvent(dst_port=air,
                     src_port=earth,
                     vars_to_map=[
                         ('air__density', 'earth_surface__temperature'),
                     ]),
    ])

    bar = PortEvent(port=earth)

    with EventManager((
        (foo, 1.),
        (bar, 1.2),
    )) as mngr:
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)
        assert_port_value_equal(air, 'air__density', 0.)

        mngr.run(1.)
        assert_port_value_equal(earth, 'earth_surface__temperature', 0.)
        assert_port_value_equal(air, 'air__density', 0.)

        mngr.run(2.)
        assert_port_value_equal(air, 'air__density', 1.2)
def test_two_events(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        foo = PortEvent(port="air_port")
        bar = PortEvent(port="earth_port")

        with EventManager(((foo, 1.0), (bar, 1.2))) as mngr:
            assert_port_value_equal(foo._port, "air__density", 0.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(foo._port, "air__density", 1.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(foo._port, "air__density", 1.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 0.0)

            mngr.run(1.3)
            assert_port_value_equal(foo._port, "air__density", 1.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 1.2)

            mngr.run(2.0)
            assert_port_value_equal(foo._port, "air__density", 2.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 1.2)

            for time in np.arange(2.0, 5.0, 0.1):
                mngr.run(time)
            assert mngr.time == approx(4.9)
            assert_port_value_equal(foo._port, "air__density", 4.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 4.8)

        assert_port_value_equal(foo._port, "air__density", 0.0)
        assert_port_value_equal(bar._port, "earth_surface__temperature", 0.0)
Exemplo n.º 4
0
def test_chain(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        air = get_component_instance("air_port")
        earth = get_component_instance("earth_port")

        foo = ChainEvent([
            PortEvent(port=air),
            PortMapEvent(
                dst_port=air,
                src_port=earth,
                vars_to_map=[("air__density", "earth_surface__temperature")],
            ),
        ])

        bar = PortEvent(port=earth)

        with EventManager(((foo, 1.0), (bar, 1.2))) as mngr:
            assert_port_value_equal(bar._port, "earth_surface__temperature",
                                    0.0)
            assert_port_value_equal(air, "air__density", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(earth, "earth_surface__temperature", 0.0)
            assert_port_value_equal(air, "air__density", 0.0)

            mngr.run(2.0)
            assert_port_value_equal(air, "air__density", 1.2)
Exemplo n.º 5
0
def test_one_event():
    foo = PortEvent(port='air_port')

    with EventManager(((foo, 1.), )) as mngr:
        assert_port_value_equal(foo._port, 'air__density', 0.)

        mngr.run(1.)
        assert_port_value_equal(foo._port, 'air__density', 1.)

        mngr.run(1.)
        assert_port_value_equal(foo._port, 'air__density', 1.)

        for time in np.arange(1., 2., .1):
            mngr.run(time)
        assert_port_value_equal(foo._port, 'air__density', 1.)

        mngr.run(2.)
        assert_port_value_equal(foo._port, 'air__density', 2.)

        for time in np.arange(2., 5., .1):
            mngr.run(time)
        assert_almost_equal(mngr.time, 4.9)
        assert_port_value_equal(foo._port, 'air__density', 4.)

    assert_port_value_equal(foo._port, 'air__density', 0.)
def test_one_event(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        foo = PortEvent(port="air_port")

        with EventManager(((foo, 1.0),)) as mngr:
            assert_port_value_equal(foo._port, "air__density", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(foo._port, "air__density", 1.0)

            mngr.run(1.0)
            assert_port_value_equal(foo._port, "air__density", 1.0)

            for time in np.arange(1.0, 2.0, 0.1):
                mngr.run(time)
            assert_port_value_equal(foo._port, "air__density", 1.0)

            mngr.run(2.0)
            assert_port_value_equal(foo._port, "air__density", 2.0)

            for time in np.arange(2.0, 5.0, 0.1):
                mngr.run(time)
            assert mngr.time == approx(4.9)
            assert_port_value_equal(foo._port, "air__density", 4.0)

        assert_port_value_equal(foo._port, "air__density", 0.0)
Exemplo n.º 7
0
def test_length_two(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        air = get_component_instance("air_port")
        earth = get_component_instance("earth_port")

        foo = ChainEvent([PortEvent(port=air), PortEvent(port=earth)])

        with EventManager([(foo, 1.2)]) as mngr:
            assert_port_value_equal(earth, "earth_surface__temperature", 0.0)
            assert_port_value_equal(air, "air__density", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(earth, "earth_surface__temperature", 0.0)
            assert_port_value_equal(air, "air__density", 0.0)

            mngr.run(2.0)
            assert_port_value_equal(earth, "earth_surface__temperature", 1.2)
            assert_port_value_equal(air, "air__density", 1.2)
Exemplo n.º 8
0
def test_length_two():
    air = get_component_instance('air_port')
    earth = get_component_instance('earth_port')

    foo = ChainEvent([PortEvent(port=air), PortEvent(port=earth)])

    with EventManager([
        (foo, 1.2),
    ]) as mngr:
        assert_port_value_equal(earth, 'earth_surface__temperature', 0.)
        assert_port_value_equal(air, 'air__density', 0.)

        mngr.run(1.)
        assert_port_value_equal(earth, 'earth_surface__temperature', 0.)
        assert_port_value_equal(air, 'air__density', 0.)

        mngr.run(2.)
        assert_port_value_equal(earth, 'earth_surface__temperature', 1.2)
        assert_port_value_equal(air, 'air__density', 1.2)
Exemplo n.º 9
0
def test_length_one(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        air = get_component_instance("air_port")
        foo = ChainEvent([PortEvent(port=air)])

        with EventManager(((foo, 1.0),)) as mngr:
            assert_port_value_equal(air, "air__density", 0.0)
            mngr.run(2.0)
            assert_port_value_equal(air, "air__density", 2.0)

        assert_port_value_equal(air, "air__density", 0.0)
Exemplo n.º 10
0
def test_length_one():
    air = get_component_instance('air_port')
    foo = ChainEvent([
        PortEvent(port=air),
    ])

    with EventManager(((foo, 1.), )) as mngr:
        assert_port_value_equal(air, 'air__density', 0.)
        mngr.run(2.)
        assert_port_value_equal(air, 'air__density', 2.)

    assert_port_value_equal(air, 'air__density', 0.)