Ejemplo n.º 1
0
def test_add_fluid():
    net = pandapipes.create_empty_network()
    fluid_old = pandapipes.call_lib("air")

    with pytest.raises(AttributeError, match="no fluid"):
        pandapipes.get_fluid(net)

    _add_fluid_to_net(net, fluid_old)
    fluid_new = pandapipes.create_constant_fluid("arbitrary_gas2",
                                                 "gas",
                                                 density=2,
                                                 compressibility=2)
    _add_fluid_to_net(net, fluid_new, overwrite=False)
    assert pandapipes.get_fluid(net) == fluid_old

    _add_fluid_to_net(net, fluid_new)
    assert pandapipes.get_fluid(net) == fluid_new

    net["fluid"] = "Hello"

    _add_fluid_to_net(net, fluid_new, overwrite=False)
    assert pandapipes.get_fluid(net) == "Hello"

    _add_fluid_to_net(net, fluid_new)
    assert pandapipes.get_fluid(net) == fluid_new
Ejemplo n.º 2
0
def test_add_fluid():
    net = pandapipes.create_empty_network()
    fluid_old = pandapipes.call_lib("air")

    try:
        pandapipes.get_fluid(net)
        assert False, "should'nt get here"
    except UserWarning:
        pass

    pandapipes.add_fluid_to_net(net, fluid_old)
    fluid_new = pandapipes.create_constant_fluid("arbitrary_gas2",
                                                 "gas",
                                                 density=2,
                                                 compressibility=2)
    pandapipes.add_fluid_to_net(net, fluid_new, overwrite=False)
    assert pandapipes.get_fluid(net) == fluid_old

    pandapipes.add_fluid_to_net(net, fluid_new)
    assert pandapipes.get_fluid(net) == fluid_new

    net["fluid"] = "Hello"

    pandapipes.add_fluid_to_net(net, fluid_new, overwrite=False)
    assert pandapipes.get_fluid(net) == "Hello"

    pandapipes.add_fluid_to_net(net, fluid_new)
    assert pandapipes.get_fluid(net) == fluid_new
Ejemplo n.º 3
0
def test_fluid_exceptions():
    net = pandapipes.create_empty_network(fluid="hgas")
    fluid = pandapipes.get_fluid(net)

    with pytest.raises(UserWarning,
                       match="property xyz was not defined for the fluid"):
        fluid.get_property("xyz", 100)

    prop = pandapipes.FluidProperty()
    with pytest.raises(NotImplementedError,
                       match="Please implement a proper fluid property!"):
        prop.get_at_value(100)

    with pytest.raises(
            AttributeError,
            match="Fluid 'natural_gas' not found in the fluid library."):
        pandapipes.call_lib("natural_gas")
Ejemplo n.º 4
0
def test_fluid_exceptions():
    net = pandapipes.create_empty_network(fluid="hgas")
    fluid = pandapipes.get_fluid(net)

    try:
        fluid.get_property("xyz", 100)
        assert False, "Shouldn't find property xyz!"
    except UserWarning:
        pass

    prop = pandapipes.FluidProperty()
    try:
        prop.get_property(100)
        assert False, "Shouldn't have property defined!"
    except NotImplementedError:
        pass

    try:
        pandapipes.call_lib("natural_gas")
        assert False, "Shouldn't have fluid natural_gas defined in lib!"
    except AttributeError:
        pass