Coverage for backend/flowsheetInternals/unitops/config/config_methods.py: 88%

12 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-11-06 23:27 +0000

1 

2""" 

3helpful methods for retrieving data from the configuration schema 

4""" 

5 

6from core.auxiliary.enums.unitsLibrary import get_default_unit 

7from .config_base import configuration 

8from common.config_types import * 

9 

10 

11def get_object_schema(simulation_object: "SimulationObject") -> ObjectType: 

12 """ 

13 Get the schema for a given simulation object 

14 :param (SimulationObject) simulation_object: Simulation object to get schema for 

15 """ 

16 return configuration[simulation_object.objectType] # type: ignore 

17 

18 

19def get_property_fields(key: str, property_schema: PropertyType, property_set: "PropertySet", index: int = 0) -> dict: 

20 """ 

21 Get the fields for a property info object 

22 :param (PropertyType) property_schema: Property info schema to get fields for 

23 """ 

24 return { 

25 "key": key, 

26 "set": property_set, 

27 "type": property_schema.type, 

28 "unitType": property_schema.unitType, 

29 "unit": get_default_unit(property_schema.unitType), 

30 "value": property_schema.value, 

31 "displayName": property_schema.displayName + (f" {index + 1}" if property_schema.many else ""), 

32 "index": index 

33 } 

34 

35def get_connected_port_keys(port_key: str, unit_schema: ObjectType) -> list[str]: 

36 """ 

37 Get the keys of all ports connected to the given port 

38 :param (Port) port: Port to get connected keys for 

39 """ 

40 for port_list in unit_schema.propertyPackagePorts.values(): 40 ↛ 44line 40 didn't jump to line 44 because the loop on line 40 didn't complete

41 if port_key in port_list: 

42 return port_list 

43 

44 return []