diff --git a/tools/abel/model/entity_field.py b/tools/abel/model/entity_field.py index 52a4f5cec..720b19fdc 100644 --- a/tools/abel/model/entity_field.py +++ b/tools/abel/model/entity_field.py @@ -86,7 +86,7 @@ def __init__( def __eq__(self, other): if not isinstance(other, MissingField): - raise TypeError(f'{str(other)} must be a MissingField instance') + return False standard_field_name_eq = self.std_field_name == other.std_field_name entity_guid_eq = self.entity_guid == other.entity_guid reporting_field_eq = ( @@ -396,7 +396,7 @@ def __init__( def __eq__(self, other: ...) -> bool: if not isinstance(other, DimensionalValueField): - raise TypeError(f'{str(other)} must be an DimensionalValueField instance') + return False standard_field_name_eq = self.std_field_name == other.std_field_name raw_field_name_eq = self.raw_field_name == other.raw_field_name entity_guid_eq = self.entity_guid == other.entity_guid diff --git a/tools/abel/model/from_spreadsheet.py b/tools/abel/model/from_spreadsheet.py index de25018bb..95cbb6e48 100644 --- a/tools/abel/model/from_spreadsheet.py +++ b/tools/abel/model/from_spreadsheet.py @@ -75,11 +75,11 @@ def LoadFieldsFromSpreadsheet( entity_field_entries: List[Dict[str, str]], guid_to_entity_map: GuidToEntityMap, ) -> List[FieldTranslation]: - """Loads list of entity field maps into FieldTranslation instances. + """Loads list of entity fields from a spreadsheet into FieldTranslation + instances. Once the entity field mapping is loaded into an FieldTranslation instance, - it - is then added to the ABEL internal model. + it is then added to the ABEL internal model. Args: entity_field_entries: A list of python dictionaries mapping entity field diff --git a/tools/abel/model/model_builder.py b/tools/abel/model/model_builder.py index f22925333..2b55d55fe 100644 --- a/tools/abel/model/model_builder.py +++ b/tools/abel/model/model_builder.py @@ -199,6 +199,17 @@ def Build(self) -> ...: Returns: built Model instance """ + # First add states to fields + for field in self.fields: + # For each state in the model + if isinstance(field, MultistateValueField): + for state in self.states: + # Create edges between states and their corresponding Multi-state + # value field in stances. + if state.reporting_entity_guid == field.reporting_entity_guid: + if state.std_field_name in (field.reporting_entity_field_name, + field.std_field_name): + field.AddState(state) self.site.entities = self.entities # For each entity, Add connections where entity is the source for guid in self.site.entities: @@ -208,17 +219,6 @@ def Build(self) -> ...: entity.AddConnection(connection) # For each field in the model for field in self.fields: - # For each state in the model - for state in self.states: - # Create edges between states and their corresponding Multi-state - # value field in stances. - if state.reporting_entity_guid == guid: - if state.std_field_name in ( - field.reporting_entity_field_name, - field.std_field_name, - ): - if isinstance(field, MultistateValueField): - field.AddState(state) # Link field to entity if entity is virtual if isinstance(entity, VirtualEntity): if field.entity_guid == guid: diff --git a/tools/abel/tests/entity_field_test.py b/tools/abel/tests/entity_field_test.py index 62234581e..f1bab4c37 100644 --- a/tools/abel/tests/entity_field_test.py +++ b/tools/abel/tests/entity_field_test.py @@ -94,8 +94,7 @@ def testMissingFieldEqualityRaisesTypeError(self): test_missing_field = MissingField.FromDict(TEST_MISSING_FIELD_DICT) # pylint: disable=unnecessary-dunder-call - with self.assertRaises(TypeError): - test_missing_field.__eq__('not a field') + self.assertFalse(test_missing_field.__eq__('not a field')) @mock.patch.object(GuidToEntityMap, 'GetEntityCodeByGuid') def testMissingFieldGetSpreadsheetRowMapping(self, test_get_code):