Skip to content

Commit

Permalink
test: update dto fuel consumer test
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehk committed Dec 11, 2024
1 parent ca05d8d commit 2b858d9
Showing 1 changed file with 1 addition and 77 deletions.
78 changes: 1 addition & 77 deletions tests/libecalc/dto/test_fuel_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_installation(installation_name: str, fuel_consumer: components.FuelConsu
fuel_consumer: a fuel consumer object, e.g. a generator, compressor or boiler
Returns:
components.Installation
dto.Installation
"""
return components.Installation(
name=installation_name,
Expand Down Expand Up @@ -108,79 +108,3 @@ def test_missing_fuel(self):
user_defined_category="category",
)
assert "Missing fuel for fuel consumer 'test'" in str(exc_info.value)

def test_duplicate_fuel_names(self):
"""
TEST SCOPE: Check that duplicate fuel type names are not allowed.
Duplicate fuel type names should not be allowed across installations.
Duplicate names may lead to debug problems and overriding of previous
values without user noticing. This test checks that different fuels cannot
have same name.
"""
fuel_consumer1 = get_fuel_consumer(
consumer_name="flare",
fuel_type=get_fuel("fuel1", emission_name="co2"),
category={Period(datetime(2000, 1, 1)): libecalc.dto.types.ConsumerUserDefinedCategoryType.FLARE},
)

fuel_consumer2 = get_fuel_consumer(
consumer_name="boiler",
fuel_type=get_fuel("fuel1", emission_name="ch4"),
category={Period(datetime(2000, 1, 1)): libecalc.dto.types.ConsumerUserDefinedCategoryType.BOILER},
)

installation1 = get_installation("INST1", fuel_consumer1)
installation2 = get_installation("INST2", fuel_consumer2)

with pytest.raises(ValidationError) as exc_info:
components.Asset(
name="multiple_installations_asset",
installations=[
installation1,
installation2,
],
)

assert "Duplicated names are: fuel1" in str(exc_info.value)

def test_same_fuel(self):
"""
TEST SCOPE: Check that validation of duplicate fuel type names do not reject
when same fuel is used across installations.
Even though duplicate fuel type names are not allowed across installations,
it should be possible to reuse the same fuel. This test verifies that this still
works.
"""

fuel_consumer1 = get_fuel_consumer(
consumer_name="flare",
fuel_type=get_fuel("fuel1", emission_name="co2"),
category={Period(datetime(2000, 1, 1)): libecalc.dto.types.ConsumerUserDefinedCategoryType.FLARE},
)

fuel_consumer2 = get_fuel_consumer(
consumer_name="boiler",
fuel_type=get_fuel("fuel1", emission_name="co2"),
category={Period(datetime(2000, 1, 1)): libecalc.dto.types.ConsumerUserDefinedCategoryType.BOILER},
)

installation1 = get_installation("INST1", fuel_consumer1)
installation2 = get_installation("INST2", fuel_consumer2)

asset = components.Asset(
name="multiple_installations_asset",
installations=[
installation1,
installation2,
],
)
fuel_types = []
for inst in asset.installations:
for fuel_consumer in inst.fuel_consumers:
for fuel_type in fuel_consumer.fuel.values():
if fuel_type not in fuel_types:
fuel_types.append(fuel_type)

assert len(fuel_types) == 1

0 comments on commit 2b858d9

Please sign in to comment.