Beispiel #1
0
def test_rerun_with_print():
    del_component_instances(['earth_port'])

    contents = """
name: earth_port
class: EarthPort

print:
- name: earth_surface__temperature
  interval: 20
  format: vtk
    """
    comp = Component.from_string(contents)
    comp.go()

    assert_equal(comp._port.current_time, 100.)
    for i in xrange(5):
        assert_isfile_and_remove('earth_surface__temperature_%04d.vtu' % i)

    del_component_instances(['earth_port'])

    comp = Component.from_string(contents)
    comp.go()

    assert_equal(comp._port.current_time, 100.)
    for i in xrange(5):
        assert_isfile_and_remove('earth_surface__temperature_%04d.vtu' % i)
Beispiel #2
0
def test_print_events():
    del_component_instances(['earth_port'])

    contents = """
name: earth_port
class: EarthPort
print:
- name: earth_surface__temperature
  interval: 0.1
  format: nc
- name: earth_surface__density
  interval: 20.
  format: vtk
- name: glacier_top_surface__slope
  interval: 0.3
  format: nc
    """
    comp = Component.from_string(contents)
    comp.go()

    assert_equal(comp._port.current_time, 100.)
    assert_isfile_and_remove('earth_surface__temperature.nc')
    assert_isfile_and_remove('glacier_top_surface__slope.nc')
    for i in xrange(5):
        assert_isfile_and_remove('earth_surface__density_%04d.vtu' % i)
Beispiel #3
0
def test_print_events(tmpdir, with_no_components):
    air_init_string = """
name: air_port
class: AirPort
print:
- name: air__temperature
  interval: 25.
  format: nc
"""
    earth_init_string = """
name: earth_port
class: EarthPort
print:
- name: glacier_top_surface__slope
  interval: 20.
  format: nc
"""
    with tmpdir.as_cwd():
        for _ in range(2):
            del_component_instances(["air_port", "earth_port"])

            air = Component.from_string(air_init_string)
            earth = Component.from_string(earth_init_string)
            earth.connect("air_port", air)
            air.connect("earth_port", earth)
            earth.go()

            assert os.path.isfile("glacier_top_surface__slope.nc")
            assert os.path.isfile("air__temperature.nc")
Beispiel #4
0
def test_model_load():
    del_component_instances(['air_port'])
    with cd_temp() as _:
        os.mkdir('air')
        model = Model.load(AIR_PORT_CONTENTS)

        assert_equal(model.components, ['air_port'])
def test_print_events():
    del_component_instances(['air_port', 'earth_port'])

    air = Component.from_string("""
name: air_port
class: AirPort
print:
- name: air__temperature
  interval: 25.
  format: vtk
""")
    earth = Component.from_string("""
name: earth_port
class: EarthPort
print:
- name: glacier_top_surface__slope
  interval: 20.
  format: vtk
""")
    earth.connect('air_port', air)
    earth.go()

    for i in xrange(5):
        assert_isfile_and_remove('glacier_top_surface__slope_%04d.vtu' % i)
    for i in xrange(4):
        assert_isfile_and_remove('air__temperature_%04d.vtu' % i)
def test_model_load(tmpdir, with_no_components):
    del_component_instances(["air_port"])
    with tmpdir.as_cwd():
        os.mkdir("air")
        model = Model.load(AIR_PORT_CONTENTS)

        assert model.components == ["air_port"]
def test_rerun_with_print(tmpdir, with_no_components):
    del_component_instances(["earth_port"])

    contents = """
name: earth_port
class: EarthPort

print:
- name: earth_surface__temperature
  interval: 20
  format: netcdf
    """
    with tmpdir.as_cwd():
        comp = Component.from_string(contents)
        comp.go()

        assert comp._port.current_time == approx(100.0)
        assert os.path.isfile("earth_surface__temperature.nc")
        # os.remove("earth_surface__temperature.nc")

        del_component_instances(["earth_port"])

        comp = Component.from_string(contents)
        comp.go()

        assert comp._port.current_time == approx(100.0)
        assert os.path.isfile("earth_surface__temperature.nc")
def test_print_events(tmpdir, with_no_components):
    del_component_instances(["earth_port"])

    contents = """
name: earth_port
class: EarthPort
print:
- name: earth_surface__temperature
  interval: 0.1
  format: nc
- name: earth_surface__density
  interval: 20.
  format: netcdf
- name: glacier_top_surface__slope
  interval: 0.3
  format: nc
    """
    with tmpdir.as_cwd():
        comp = Component.from_string(contents)
        comp.go()

        assert comp._port.current_time == 100.0
        assert os.path.isfile("earth_surface__temperature.nc")
        assert os.path.isfile("glacier_top_surface__slope.nc")
        assert os.path.isfile("earth_surface__density.nc")
Beispiel #9
0
def test_rerun():
    del_component_instances(['AirPort'])

    comp = Component('AirPort', uses=[], provides=[], events=[])
    comp.go()
    assert_equal(comp._port.current_time, 100.)

    comp.go()
    assert_equal(comp._port.current_time, 100.)
def test_model_from_file(tmpdir, with_no_components):
    del_component_instances(["air_port"])
    with tmpdir.as_cwd():
        os.mkdir("air")
        with open("components.yml", "w") as fp:
            fp.write(AIR_PORT_CONTENTS)
        model = Model.from_file("components.yml")

        assert model.components == ["air_port"]
Beispiel #11
0
def test_model_from_file():
    del_component_instances(['air_port'])
    with cd_temp() as _:
        os.mkdir('air')
        with open('components.yml', 'w') as fp:
            fp.write(AIR_PORT_CONTENTS)
        model = Model.from_file('components.yml')

        assert_equal(model.components, ['air_port'])
def test_rerun(with_no_components):
    del_component_instances(["AirPort"])

    comp = Component("AirPort", uses=[], provides=[], events=[])
    comp.go()
    assert comp._port.current_time == 100.0

    comp.go()
    assert comp._port.current_time == 100.0
Beispiel #13
0
def test_from_string():
    del_component_instances(['air_port'])

    contents = """
name: air_port
class: AirPort
    """
    comp = Component.from_string(contents)
    comp.go()
    assert_equal(comp._port.current_time, 100.)
def test_from_string(with_no_components):
    del_component_instances(["air_port"])

    contents = """
name: air_port
class: AirPort
    """
    comp = Component.from_string(contents)
    comp.go()
    assert comp._port.current_time == 100.0
Beispiel #15
0
def test_no_events():
    del_component_instances(['air_port', 'earth_port'])

    air = Component('AirPort', name='air_port', uses=[], provides=[], events=[])
    earth = Component('EarthPort', name='earth_port', uses=['air_port', ],
                      provides=[],  events=[])
    earth.connect('air_port', air)
    air.connect('earth_port', earth)
    earth.go()

    assert_equal(air._port.current_time, 100.)
    assert_equal(earth._port.current_time, 100.)
Beispiel #16
0
def test_no_events(with_no_components):
    del_component_instances(["air_port", "earth_port"])

    air = Component("AirPort", name="air_port", uses=[], provides=[], events=[])
    earth = Component(
        "EarthPort", name="earth_port", uses=["air_port"], provides=[], events=[]
    )
    earth.connect("air_port", air)
    earth.go()

    assert earth._port.current_time == 100.0
    assert air._port.current_time == 100.0