Skip to content

Commit

Permalink
Merge pull request #1269 from google/iv-enumerations-messaging
Browse files Browse the repository at this point in the history
update entity_instance.py
  • Loading branch information
trav3711 authored Feb 13, 2024
2 parents cd35bf7 + e7ea496 commit 79e7a27
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tools/validators/instance_validator/validate/entity_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,16 @@ def _IsAllMissingFields(self, entity: EntityInstance) -> bool:
return True
return False

def _ValidateEnumerations(self, entity_translation: Dict[str, Any]) -> bool:
def _ValidateEnumerations(self, entity: EntityInstance) -> bool:
"""Validate that a translation is properly enumerated.
Args:
entity_translation: Dictionary of written field names to
FieldTranslation instances.
entity: Instance of EntityInstance.
Returns:
"""
entity_translation = entity.translation
enumeration_map = {}
is_valid = True
for written_field_name in entity_translation:
Expand All @@ -520,8 +520,9 @@ def _ValidateEnumerations(self, entity_translation: Dict[str, Any]) -> bool:
enumeration_map[base_field_name] = [1, 0]
for base_field_mapping, enum_list in enumeration_map.items():
if enum_list[0] > enum_list[1] and enum_list != [1, 0]:
print(f'[ERROR]\t field name {base_field_name} is enumerated and '
'un-enumerated in the same translation block.')
print(f'[ERROR]\t {entity.guid}: {entity.code} has field name'
f' {base_field_name} which is enumerated and '
'not enumerated in the same translation block.')
is_valid = False
return is_valid

Expand Down Expand Up @@ -554,7 +555,7 @@ def _ValidateTranslation(
if self._IsAllMissingFields(entity):
return False

is_valid = self._ValidateEnumerations(entity.translation)
is_valid = self._ValidateEnumerations(entity)
# Check that defined fields are in the type
for as_written_field_name, ft in entity.translation.items():
qualified_field_name = _GetAllowedField(
Expand Down

0 comments on commit 79e7a27

Please sign in to comment.