Skip to content

Commit

Permalink
get_sequence_item returns NcMethodResult
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-r-thorpe committed Nov 1, 2024
1 parent bd4099c commit ebd79bc
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 78 deletions.
6 changes: 1 addition & 5 deletions nmostesting/IS12Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,12 @@ def invoke_method_override(self, test, method_id, argument, oid, **kwargs):
method_id,
{"argument": argument})

def get_sequence_item(self, test, property_id, index, oid, **kwargs):
def get_sequence_item_override(self, test, property_id, index, oid, **kwargs):
"""Get value from sequence property. Raises NMOSTestException on error"""
return self.execute_command(test, oid,
NcObjectMethods.GET_SEQUENCE_ITEM.value,
{'id': property_id, 'index': index})

def get_sequence_item_value(self, test, property_id, index, oid, **kwargs):
"""Get value from sequence property. Raises NMOSTestException on error"""
return self.get_sequence_item(test, property_id, index, oid=oid)['value']

def set_sequence_item(self, test, property_id, index, value, oid, **kwargs):
"""Add value to a sequence property. Raises NMOSTestException on error"""
return self.execute_command(test, oid,
Expand Down
5 changes: 1 addition & 4 deletions nmostesting/IS14Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,12 @@ def invoke_method_override(self, test, method_id, argument, role_path, **kwargs)
methods_endpoint = self._create_methods_endpoint(role_path, method_id)
return self._do_request(test, "PATCH", methods_endpoint, json={"arguments": argument})

def get_sequence_item(self, test, property_id, index, role_path, **kwargs):
def get_sequence_item_override(self, test, property_id, index, role_path, **kwargs):
"""Get value from sequence property. Raises NMOSTestException on error"""
methods_endpoint = self._create_methods_endpoint(role_path, NcObjectMethods.GET_SEQUENCE_ITEM.value)
return self._do_request(test, "PATCH", methods_endpoint,
json={"arguments": {"id": property_id, "index": index}})

def get_sequence_item_value(self, test, property_id, index, role_path, **kwargs):
return self.get_sequence_item(test, property_id, index, role_path, **kwargs)["value"]

def get_sequence_length(self, test, property_id, role_path, **kwargs):
"""Get sequence length. Raises NMOSTestException on error"""
methods_endpoint = self._create_methods_endpoint(role_path, NcObjectMethods.GET_SEQUENCE_LENGTH.value)
Expand Down
12 changes: 7 additions & 5 deletions nmostesting/MS05Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ def set_property_override(self, test, property_id, argument, **kwargs):
def invoke_method_override(self, test, method_id, argument, **kwargs):
pass

def get_sequence_item(self, test, property_id, index, **kwargs):
pass

def get_sequence_item_value(self, test, property_id, index, **kwargs):
"""Get value from sequence property. Raises NMOSTestException on error"""
def get_sequence_item_override(self, test, property_id, index, **kwargs):
pass

def get_sequence_length(self, test, property_id, **kwargs):
Expand Down Expand Up @@ -122,6 +118,12 @@ def invoke_method(self, test, method_id, argument, **kwargs):
role_path=kwargs.get("role_path"))
return NcMethodResult.factory(result)

def get_sequence_item(self, test, property_id, index, **kwargs):
result = self.get_sequence_item_override(test, property_id, index, **kwargs)
self.reference_datatype_schema_validate(test, result, NcMethodResult.__name__,
role_path=kwargs.get("role_path"))
return NcMethodResult.factory(result)

def query_device_model(self, test):
""" Query Device Model from the Node under test.
self.device_model_metadata set on Device Model validation error.
Expand Down
48 changes: 23 additions & 25 deletions nmostesting/suites/MS0501Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ..GenericTest import GenericTest, NMOSTestException
from ..MS05Utils import MS05Utils, NcBlock, NcBlockMemberDescriptor, NcBlockProperties, NcClassDescriptor, \
NcDatatypeDescriptor, NcDatatypeDescriptorStruct, NcDeviceManagerProperties, NcMethodResultError, NcMethodStatus, \
NcMethodResult, NcObjectProperties, NcParameterConstraintsNumber, NcParameterConstraintsString, \
NcObjectProperties, NcParameterConstraintsNumber, NcParameterConstraintsString, \
NcPropertyConstraintsNumber, NcPropertyConstraintsString, NcTouchpoint, NcTouchpointNmos, \
NcTouchpointNmosChannelMapping, StandardClassIds
from ..TestResult import Test
Expand Down Expand Up @@ -199,22 +199,23 @@ def _validate_property_type(self, test, value, property_descriptor, role_path):

def check_get_sequence_item(self, test, oid, role_path, sequence_values, property_descriptor):
context = f"{self.ms05_utils.create_role_path_string(role_path)}: "
try:
self.get_sequence_item_metadata.checked = True
sequence_index = 0
for property_value in sequence_values:
value = self.ms05_utils.get_sequence_item_value(test, property_descriptor.id.__dict__, sequence_index,
oid=oid, role_path=role_path)
if property_value != value:
self.get_sequence_item_metadata.error = True
self.get_sequence_item_metadata.error_msg += \
f"{context}{property_descriptor.name}: Expected: {str(property_value)}, Actual: {str(value)}" \
f" at index {sequence_index}, "
sequence_index += 1
except NMOSTestException as e:
self.get_sequence_item_metadata.error = True
self.get_sequence_item_metadata.error_msg += \
f"{context}{property_descriptor.name}: {str(e.args[0].detail)}, "
self.get_sequence_item_metadata.checked = True
sequence_index = 0
for property_value in sequence_values:
method_result = self.ms05_utils.get_sequence_item(test, property_descriptor.id.__dict__,
sequence_index, oid=oid, role_path=role_path)
if isinstance(method_result, NcMethodResultError):
self.get_sequence_item_metadata.error = True
self.get_sequence_item_metadata.error_msg += \
f"{context}{property_descriptor.name}: Error getting sequence item: " \
f"{method_result.error}, "
if property_value != method_result.value:
self.get_sequence_item_metadata.error = True
self.get_sequence_item_metadata.error_msg += \
f"{context}{property_descriptor.name}: Expected: {str(property_value)}, " \
f"Actual: {str(method_result.value)} " \
f"at index {sequence_index}, "
sequence_index += 1

def check_get_sequence_length(self, test, oid, role_path, sequence_values, property_descriptor):
context = f"{self.ms05_utils.create_role_path_string(role_path)}: "
Expand Down Expand Up @@ -1366,14 +1367,11 @@ def test_ms05_26(self, test):
role_path=["root"])
out_of_bounds_index = length + 10

result = self.ms05_utils.get_sequence_item(test,
NcBlockProperties.MEMBERS.value,
out_of_bounds_index,
oid=self.ms05_utils.ROOT_BLOCK_OID,
role_path=["root"])

self.ms05_utils.reference_datatype_schema_validate(test, result, NcMethodResult.__name__)
method_result = NcMethodResult.factory(result)
method_result = self.ms05_utils.get_sequence_item(test,
NcBlockProperties.MEMBERS.value,
out_of_bounds_index,
oid=self.ms05_utils.ROOT_BLOCK_OID,
role_path=["root"])

if not isinstance(method_result, NcMethodResultError):
return test.FAIL("Sequence out of bounds error expected.",
Expand Down
96 changes: 57 additions & 39 deletions nmostesting/suites/MS0502Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,51 +811,69 @@ def test_ms05_07(self, test):
return self._do_check_methods_test(test, question)

def check_add_sequence_item(self, test, property_id, property_name, sequence_length, oid, role_path, context=""):
try:
self.add_sequence_item_metadata.checked = True
# Add a value to the end of the sequence
new_item = self.ms05_utils.get_sequence_item_value(test, property_id.__dict__, index=0,
oid=oid, role_path=role_path)

self.ms05_utils.add_sequence_item(test, property_id.__dict__, new_item, oid=oid, role_path=role_path)

# check the value
value = self.ms05_utils.get_sequence_item_value(test, property_id.__dict__, index=sequence_length,
oid=oid, role_path=role_path)
if value != new_item:
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Expected: {str(new_item)}, Actual: {str(value)}, "
return True
except NMOSTestException as e:
# Add a value to the end of the sequence
method_result = self.ms05_utils.get_sequence_item(test, property_id.__dict__, index=0,
oid=oid, role_path=role_path)

if isinstance(method_result, NcMethodResultError):
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: {str(e.args[0].detail)}, "
return False
f"{context}{property_name}: Error getting sequence item: {str(method_result.errorMessage)} "
return False
new_item = method_result.value
self.ms05_utils.add_sequence_item(test, property_id.__dict__, new_item, oid=oid, role_path=role_path)

# check the value
method_result = self.ms05_utils.get_sequence_item(test, property_id.__dict__, index=sequence_length,
oid=oid, role_path=role_path)

if isinstance(method_result, NcMethodResultError):
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Error getting sequence item: {str(method_result.errorMessage)} "
return False

value = method_result.value
if value != new_item:
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Expected: {str(new_item)}, Actual: {str(value)}, "
self.add_sequence_item_metadata.checked = True

return True

def check_set_sequence_item(self, test, property_id, property_name, sequence_length, oid, role_path, context=""):
try:
self.set_sequence_item_metadata.checked = True
new_value = self.ms05_utils.get_sequence_item_value(test, property_id.__dict__, index=sequence_length - 1,
oid=oid, role_path=role_path)

# set to another value
self.ms05_utils.set_sequence_item(test, property_id.__dict__, index=sequence_length, value=new_value,
oid=oid, role_path=role_path)

# check the value
value = self.ms05_utils.get_sequence_item_value(test, property_id.__dict__, index=sequence_length,
oid=oid, role_path=role_path)
if value != new_value:
self.set_sequence_item_metadata.error = True
self.set_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Expected: {str(new_value)}, Actual: {str(value)}, "
return True
except NMOSTestException as e:
method_result = self.ms05_utils.get_sequence_item(test, property_id.__dict__, index=sequence_length - 1,
oid=oid, role_path=role_path)

if isinstance(method_result, NcMethodResultError):
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Error getting sequence item: {str(method_result.errorMessage)} "
return False
new_value = method_result.value
# set to another value
self.ms05_utils.set_sequence_item(test, property_id.__dict__, index=sequence_length, value=new_value,
oid=oid, role_path=role_path)

# check the value
method_result = self.ms05_utils.get_sequence_item(test, property_id.__dict__, index=sequence_length,
oid=oid, role_path=role_path)

if isinstance(method_result, NcMethodResultError):
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Error getting sequence item: {str(method_result.errorMessage)} "
return False

if method_result.value != new_value:
self.set_sequence_item_metadata.error = True
self.set_sequence_item_metadata.error_msg += \
f"{context}{property_name}: {str(e.args[0].detail)}, "
return False
f"{context}{property_name}: Expected: {str(new_value)}, Actual: {str(method_result.value)}, "

self.set_sequence_item_metadata.checked = True

return True

def check_remove_sequence_item(self, test, property_id, property_name, sequence_length,
oid, role_path, context=""):
Expand Down

0 comments on commit ebd79bc

Please sign in to comment.