From 5964f72dfcb3092ecb3eac1037daa6dae099b2c0 Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Wed, 13 Mar 2024 07:28:48 +0000 Subject: [PATCH] Rename assertion attribute `value` --- lib/galaxy/tool_util/verify/asserts/image.py | 43 +++++++------ lib/galaxy/tool_util/xsd/galaxy.xsd | 34 +++++------ test/functional/tools/validation_image.xml | 64 ++++++++++---------- 3 files changed, 70 insertions(+), 71 deletions(-) diff --git a/lib/galaxy/tool_util/verify/asserts/image.py b/lib/galaxy/tool_util/verify/asserts/image.py index 6f9c1609c34..3ebd46095f9 100644 --- a/lib/galaxy/tool_util/verify/asserts/image.py +++ b/lib/galaxy/tool_util/verify/asserts/image.py @@ -49,7 +49,7 @@ def _assert_float( def assert_has_image_width( output_bytes: bytes, - value: Optional[Union[int, str]] = None, + width: Optional[Union[int, str]] = None, delta: Union[int, str] = 0, min: Optional[Union[int, str]] = None, max: Optional[Union[int, str]] = None, @@ -62,7 +62,7 @@ def assert_has_image_width( with Image.open(buf) as im: _assert_number( im.size[0], - value, + width, delta, min, max, @@ -74,7 +74,7 @@ def assert_has_image_width( def assert_has_image_height( output_bytes: bytes, - value: Optional[Union[int, str]] = None, + height: Optional[Union[int, str]] = None, delta: Union[int, str] = 0, min: Optional[Union[int, str]] = None, max: Optional[Union[int, str]] = None, @@ -87,7 +87,7 @@ def assert_has_image_height( with Image.open(buf) as im: _assert_number( im.size[1], - value, + height, delta, min, max, @@ -99,7 +99,7 @@ def assert_has_image_height( def assert_has_image_channels( output_bytes: bytes, - value: Optional[Union[int, str]] = None, + channels: Optional[Union[int, str]] = None, delta: Union[int, str] = 0, min: Optional[Union[int, str]] = None, max: Optional[Union[int, str]] = None, @@ -112,7 +112,7 @@ def assert_has_image_channels( with Image.open(buf) as im: _assert_number( len(im.getbands()), - value, + channels, delta, min, max, @@ -155,7 +155,7 @@ def _get_image( def assert_has_image_mean_intensity( output_bytes: bytes, channel: Optional[Union[int, str]] = None, - value: Optional[Union[float, str]] = None, + mean_intensity: Optional[Union[float, str]] = None, eps: Union[float, str] = 0.01, min: Optional[Union[float, str]] = None, max: Optional[Union[float, str]] = None, @@ -168,7 +168,7 @@ def assert_has_image_mean_intensity( actual=im_arr.mean(), label="mean intensity", tolerance=eps, - expected=value, + expected=mean_intensity, range_min=min, range_max=max, ) @@ -176,25 +176,24 @@ def assert_has_image_mean_intensity( def assert_has_image_center_of_mass( output_bytes: bytes, + center_of_mass: Union[Tuple[float, float], str], channel: Optional[Union[int, str]] = None, - point: Optional[Union[Tuple[float, float], str]] = None, eps: Union[float, str] = 0.01, ) -> None: """ Asserts the specified output is an image and has the specified center of mass. """ im_arr = _get_image(output_bytes, channel) - if point is not None: - if isinstance(point, str): - point_parts = [c.strip() for c in point.split(",")] - assert len(point_parts) == 2 - point = (float(point_parts[0]), float(point_parts[1])) - assert len(point) == 2, "point must have two components" - actual_center_of_mass = _compute_center_of_mass(im_arr) - distance = numpy.linalg.norm(numpy.subtract(point, actual_center_of_mass)) - assert distance <= float( - eps - ), f"Wrong center of mass: {actual_center_of_mass} (expected {point}, distance: {distance}, eps: {eps})" + if isinstance(center_of_mass, str): + center_of_mass_parts = [c.strip() for c in center_of_mass.split(",")] + assert len(center_of_mass_parts) == 2 + center_of_mass = (float(center_of_mass_parts[0]), float(center_of_mass_parts[1])) + assert len(center_of_mass) == 2, "center_of_mass must have two components" + actual_center_of_mass = _compute_center_of_mass(im_arr) + distance = numpy.linalg.norm(numpy.subtract(center_of_mass, actual_center_of_mass)) + assert distance <= float( + eps + ), f"Wrong center of mass: {actual_center_of_mass} (expected {center_of_mass}, distance: {distance}, eps: {eps})" def _get_image_labels( @@ -270,7 +269,7 @@ def assert_has_image_mean_object_size( channel: Optional[Union[int, str]] = None, labels: Optional[Union[str, List[int]]] = None, exclude_labels: Optional[Union[str, List[int]]] = None, - value: Optional[Union[float, str]] = None, + mean_object_size: Optional[Union[float, str]] = None, eps: Union[float, str] = 0.01, min: Optional[Union[float, str]] = None, max: Optional[Union[float, str]] = None, @@ -284,7 +283,7 @@ def assert_has_image_mean_object_size( actual=actual_mean_object_size, label="mean object size", tolerance=eps, - expected=value, + expected=mean_object_size, range_min=min, range_max=max, ) diff --git a/lib/galaxy/tool_util/xsd/galaxy.xsd b/lib/galaxy/tool_util/xsd/galaxy.xsd index b6b6fb10279..f9d13253511 100644 --- a/lib/galaxy/tool_util/xsd/galaxy.xsd +++ b/lib/galaxy/tool_util/xsd/galaxy.xsd @@ -2758,15 +2758,15 @@ $attribute_list::5 ``). +Asserts the output is an image and has a specific width (in pixels), +plus/minus ``delta`` (e.g., ````). Alternatively the range of the expected width can be specified by ``min`` and/or ``max``. $attribute_list::5 ]]> - + Expected width of the image (in pixels).` @@ -2791,15 +2791,15 @@ $attribute_list::5 ``). +Asserts the output is an image and has a specific height (in pixels), +plus/minus ``delta`` (e.g., ````). Alternatively the range of the expected height can be specified by ``min`` and/or ``max``. $attribute_list::5 ]]> - + Expected height of the image (in pixels).` @@ -2824,15 +2824,15 @@ $attribute_list::5 ``). +Asserts the output is an image and has a specific number of channels, +plus/minus ``delta`` (e.g., ````). Alternatively the range of the expected number of channels can be specified by ``min`` and/or ``max``. $attribute_list::5 ]]> - + Expected number of channels of the image.` @@ -2857,15 +2857,15 @@ $attribute_list::5 ``). +Asserts the output is an image and has a specific mean intensity value, +plus/minus ``eps`` (e.g., ````). Alternatively the range of the expected mean intensity value can be specified by ``min`` and/or ``max``. $attribute_list::5 ]]> - + The required mean value of the image intensities. @@ -2894,15 +2894,15 @@ $attribute_list::5 ``). +````). $attribute_list::5 ]]> - + The required center of mass of the image intensities (horizontal and vertical coordinate, separated by a comma). @@ -2970,14 +2970,14 @@ $attribute_list::5 ``). +plus/minus ``eps`` (e.g., ````). The labels must be unique. $attribute_list::5 ]]> - + The required mean size of the uniquely labeled objects. diff --git a/test/functional/tools/validation_image.xml b/test/functional/tools/validation_image.xml index c6358479686..dd79503a357 100644 --- a/test/functional/tools/validation_image.xml +++ b/test/functional/tools/validation_image.xml @@ -14,10 +14,10 @@ - - - - + + + + @@ -25,7 +25,7 @@ - + @@ -33,7 +33,7 @@ - + @@ -41,15 +41,15 @@ - - - - - - - - - + + + + + + + + + @@ -57,7 +57,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -98,11 +98,11 @@ - - - + + + - + @@ -110,11 +110,11 @@ - - - + + + - + @@ -122,7 +122,7 @@ - + @@ -130,7 +130,7 @@ - + @@ -138,7 +138,7 @@ - + @@ -146,11 +146,11 @@ - - - + + + - +