Skip to content

Commit

Permalink
Consistent formatting of error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-r-thorpe committed Nov 15, 2024
1 parent 2cbb4c0 commit dbdc5df
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 108 deletions.
24 changes: 10 additions & 14 deletions nmostesting/MS05Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,12 @@ def queried_datatype_schema_validate(self, test, payload, datatype_name, role_pa
raise NMOSTestException(test.FAIL(f"Unable to create Device Model schemas: {e.message}"))

self._validate_schema(test, payload, self.datatype_schemas.get(datatype_name),
f"{self.create_role_path_string(role_path)}: {datatype_name}: ")
f"role path={self.create_role_path_string(role_path)}: datatype={datatype_name}: ")

def reference_datatype_schema_validate(self, test, payload, datatype_name, role_path=None):
"""Validate payload against specification reference datatype schema"""
self._validate_schema(test, payload, self.reference_datatype_schemas.get(datatype_name),
f"{self.create_role_path_string(role_path)}: {datatype_name}: ")
f"role path={self.create_role_path_string(role_path)}: datatype={datatype_name}: ")

def _validate_schema(self, test, payload, schema, context=""):
"""Delegates to jsonschema validate. Raises NMOSTestExceptions on error"""
Expand All @@ -432,7 +432,8 @@ def _validate_schema(self, test, payload, schema, context=""):
checker = FormatChecker(["ipv4", "ipv6", "uri"])
validate(payload, schema, format_checker=checker)
except ValidationError as e:
raise NMOSTestException(test.FAIL(f"{context}Schema validation error: {e.message}"))
raise NMOSTestException(test.FAIL(f"{context}Schema validation error: {e.message}. "
"Note that error may originate from a subschema of this schema."))
except SchemaError as e:
raise NMOSTestException(test.FAIL(f"{context}Schema error: {e.message}"))

Expand Down Expand Up @@ -496,7 +497,7 @@ def _get_class_manager_datatype_descriptors(self, test, class_manager_oid, role_
oid=class_manager_oid, role_path=role_path)

if isinstance(method_result, NcMethodResultError):
raise NMOSTestException(test.FAIL(f"{self.create_role_path_string(role_path)}: "
raise NMOSTestException(test.FAIL(f"role path={self.create_role_path_string(role_path)}: "
"Error getting Class Manager Datatype property: "
f"{str(method_result.errorMessage)}"))

Expand All @@ -518,7 +519,7 @@ def _get_class_manager_class_descriptors(self, test, class_manager_oid, role_pat
oid=class_manager_oid, role_path=role_path)

if isinstance(method_result, NcMethodResultError):
raise NMOSTestException(test.FAIL(f"{self.create_role_path_string(role_path)}: "
raise NMOSTestException(test.FAIL(f"role path={self.create_role_path_string(role_path)}: "
"Error getting Class Manager Control Classes property: "
f"{str(method_result.errorMessage)}"))

Expand All @@ -542,7 +543,7 @@ def create_block(self, test, class_id, oid, role, base_role_path=None, member_de
oid=oid, role_path=role_path)

if isinstance(method_result, NcMethodResultError):
raise NMOSTestException(test.FAIL(f"{self.create_role_path_string(role_path)}: "
raise NMOSTestException(test.FAIL(f"role path={self.create_role_path_string(role_path)}: "
"Unable to get runtime property constraints: "
f"{str(method_result.errorMessage)}"))

Expand All @@ -559,12 +560,12 @@ def create_block(self, test, class_id, oid, role, base_role_path=None, member_de
oid=oid, role_path=role_path)

if isinstance(method_result, NcMethodResultError):
raise NMOSTestException(test.FAIL(f"{self.create_role_path_string(role_path)}: "
raise NMOSTestException(test.FAIL(f"role path={self.create_role_path_string(role_path)}: "
"Unable to get members property: "
f"{str(method_result.errorMessage)}"))

if method_result.value is None or not isinstance(method_result.value, list):
raise NMOSTestException(test.FAIL(f"{self.create_role_path_string(role_path)}: "
raise NMOSTestException(test.FAIL(f"role path={self.create_role_path_string(role_path)}: "
"Block members not a list: "
f"{str(method_result.value)}"))

Expand Down Expand Up @@ -605,11 +606,6 @@ def _get_singleton_object_by_class_id(self, test, class_id):
if len(members) == 0:
raise NMOSTestException(test.FAIL(f"Class: {class_id} not found in Root Block.", spec_link))

if len(members) > 1:
error_msg_base = f"Found members: {[m.role for m in members].join(', ')}: "
raise NMOSTestException(test.FAIL(f"{error_msg_base}Class: {class_id} expected to be a singleton.",
spec_link))

return members[0]

def get_class_manager(self, test):
Expand Down Expand Up @@ -692,7 +688,7 @@ def create_role_path(self, base_role_path, role):
def create_role_path_string(self, role_path):
if role_path is None or not isinstance(role_path, list):
return ""
return "/".join([str(r) for r in role_path])
return f"/{'/'.join([str(r) for r in role_path])}"

def create_class_id_string(self, class_id):
if class_id is None or not isinstance(class_id, list):
Expand Down
Loading

0 comments on commit dbdc5df

Please sign in to comment.