Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup(self):
self.nw = network(['water', 'air'])
self.comp = combustion.combustion_engine('combustion engine')
self.pipe = piping.pipe('pipe')
self.conn = connection(self.comp, 'out1', self.pipe, 'in1')
self.bus = bus('mybus')
self.sub = subsystems.subsystem('MySub')
def setup(self):
self.nw = network(['water', 'air'])
self.instance = combustion.combustion_engine('combustion engine')
self.bus = bus('power')
self.bus.add_comps({'c': self.instance, 'p': 'Param'})
def test_get_attr_errors():
"""Test errors of get_attr methods."""
nw = network(['water', 'air'])
comb = combustion.combustion_engine('combustion engine')
pipeline = piping.pipe('pipeline')
conn = connection(comb, 'out1', pipeline, 'in1')
mybus = bus('mybus')
sub = subsystems.subsystem('MySub')
get_attr_KeyError(comb, 'wow')
get_attr_KeyError(conn, 'key')
get_attr_KeyError(mybus, 'components')
get_attr_KeyError(nw, 'missing')
get_attr_KeyError(ref(conn, 1, 0), 'comp')
get_attr_KeyError(sub, 'test')
get_attr_KeyError(char_line(), 'test')
get_attr_KeyError(data_container(), 'somekey')
get_attr_KeyError(char_map(), 'Stuff')
def test_ref_creation_error():
"""Test errors creating reference objects."""
comb = combustion.combustion_engine('combustion engine')
pipeline = piping.pipe('pipeline')
conn = connection(comb, 'out1', pipeline, 'in1')
create_ref_TypeError([conn, 7, 'hi'])
create_ref_TypeError([conn, 'hi', 0])
create_ref_TypeError([comb, 1, 0])
def test_bus_add_comps_errors():
"""Test errors adding components to busses."""
mybus = bus('mybus')
comb = combustion.combustion_engine('combustion engine')
pipeline = piping.pipe('pipeline')
conn = connection(comb, 'out1', pipeline, 'in1')
bus_add_comps_TypeError(mybus, {'comp': conn})
bus_add_comps_TypeError(mybus, {'f': comb})
bus_add_comps_TypeError(mybus, {'comp': comb, 'char': 'Hi'})
bus_add_comps_TypeError(mybus, {'comp': comb, 'param': 5})
bus_add_comps_TypeError(mybus, {'comp': comb, 'P_ref': 'what'})
bus_add_comps_TypeError(mybus, comb)
with raises(ValueError):
mybus.add_comps({'comp': comb, 'base': 5})
def test_connection_creation_ValueError():
"""Test ValueErrors creating connections."""
comb = combustion.combustion_engine('combustion engine')
pipeline = piping.pipe('pipeline')
with raises(ValueError):
connection(comb, 'out6', pipeline, 'in1')
with raises(ValueError):
connection(comb, 'out1', pipeline, 'in5')
def setup(self):
self.nw = network(['water', 'air'])
self.instance = combustion.combustion_engine('combustion engine')
self.bus = bus('power')
self.bus.add_comps({'comp': self.instance, 'param': 'Param'})
def test_set_attr_errors():
"""Test errors of set_attr methods."""
nw = network(['water', 'air'])
comb = combustion.combustion_engine('combustion engine')
pipeline = piping.pipe('pipeline')
conn = connection(comb, 'out1', pipeline, 'in1')
mybus = bus('mybus')
# ValueErrors
set_attr_ValueError(comb, offdesign=['Q'])
set_attr_ValueError(conn, offdesign=['f'])
set_attr_ValueError(nw, m_unit='kg')
set_attr_ValueError(nw, h_unit='kg')
set_attr_ValueError(nw, p_unit='kg')
set_attr_ValueError(nw, T_unit='kg')
set_attr_ValueError(nw, v_unit='kg')
set_attr_ValueError(conn, state=5)
if (inconn.fluid.val_set[fluid] is False and
inconn.good_starting_values is False):
inconn.fluid.val[fluid] = x
self.init_source(inconn, start)
if isinstance(c.source, merge):
for inconn in self.comps.loc[c.source, 'inlets']:
for fluid, x in c.fluid.val.items():
if (inconn.fluid.val_set[fluid] is False and
inconn.good_starting_values is False):
inconn.fluid.val[fluid] = x
self.init_source(inconn, start)
if isinstance(c.source, combustion_engine):
for inconn in self.comps.loc[c.source, 'inlets'][:2]:
for fluid, x in c.fluid.val.items():
if (inconn.fluid.val_set[fluid] is False and
inconn.good_starting_values is False):
inconn.fluid.val[fluid] = x
self.init_source(inconn, start)
if isinstance(c.source, drum) and c.source != start:
start = c.source
for inconn in self.comps.loc[c.source, 'inlets']:
for fluid, x in c.fluid.val.items():
if (inconn.fluid.val_set[fluid] is False and
inconn.good_starting_values is False):
inconn.fluid.val[fluid] = x
from tespy.tools.data_containers import dc_prop
from tespy.tools.data_containers import dc_simple
from tespy.tools.helpers import modify_path_os
# pass the warning messages to the logger
logging.captureWarnings(True)
comp_target_classes = {
'cycle_closer': basics.cycle_closer,
'sink': basics.sink,
'source': basics.source,
'subsystem_interface': basics.subsystem_interface,
'combustion_chamber': combustion.combustion_chamber,
'combustion_chamber_stoich': combustion.combustion_chamber_stoich,
'combustion_engine': combustion.combustion_engine,
'orc_evaporator': customs.orc_evaporator,
'condenser': heat_exchangers.condenser,
'desuperheater': heat_exchangers.desuperheater,
'heat_exchanger': heat_exchangers.heat_exchanger,
'heat_exchanger_simple': heat_exchangers.heat_exchanger_simple,
'solar_collector': heat_exchangers.solar_collector,
'parabolic_trough': heat_exchangers.parabolic_trough,
'droplet_separator': nodes.droplet_separator,
'drum': nodes.drum,
'merge': nodes.merge,
'node': nodes.node,
'separator': nodes.separator,
'splitter': nodes.splitter,
'pipe': piping.pipe,
'valve': piping.valve,
'water_electrolyzer': reactors.water_electrolyzer,