Skip to content

Commit

Permalink
tests(disordered_tracing): Bulks out missing unittests
Browse files Browse the repository at this point in the history
Making a start on the backlog/deficit of unit-tests highlighted in #966.
  • Loading branch information
ns-rse committed Oct 22, 2024
1 parent ee0fb0f commit 8b91408
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
38 changes: 31 additions & 7 deletions tests/tracing/test_disordered_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,12 +1452,12 @@ def test_compile_skan_stats() -> None:

@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_segment_heights() -> None:
"""Test of prep_segment_heights()."""
"""Test of segment_heights()."""


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_segment_middles() -> None:
"""Test of prep_segment_middles()."""
"""Test of segment_middles()."""


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
Expand All @@ -1470,16 +1470,40 @@ def test_prep_arrays() -> None:
"""Test of prep_arrays()."""


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_grain_anchor() -> None:
@pytest.mark.parametrize(
("array_shape", "bounding_box", "pad_width", "target"),
[
pytest.param((3, 3), [1, 1, 2, 2], 1, (0, 0), id="Simple square padded by 1 to edges"),
pytest.param((3, 3), [1, 1, 2, 2], 2, (0, 0), id="Simple square padded by 2 beyond both edges"),
pytest.param((3, 10), [1, 1, 2, 2], 4, (0, 0), id="Simple square padded by 4 beyond rows but within columns"),
pytest.param((10, 10), [7, 7, 9, 9], 4, (3, 3), id="Simple square padded by 4 beyond bottom and right edges"),
],
)
def test_grain_anchor(array_shape: tuple, bounding_box: list, pad_width: int, target: npt.NDArray) -> None:
"""Test of grain_anchor()."""
grain_anchor = disordered_tracing.grain_anchor(array_shape, bounding_box, pad_width)
assert grain_anchor == target


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_get_skan_image() -> None:
"""Test of grain_anchor()."""
"""Test of get_skan_image()."""


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_pad_bounding_box() -> None:
@pytest.mark.parametrize(
("array_shape", "bounding_box", "pad_width", "target"),
[
pytest.param((3, 3), [1, 1, 2, 2], 1, [0, 0, 3, 3], id="Simple square padded by 1 to edges"),
pytest.param((3, 3), [1, 1, 2, 2], 2, [0, 0, 3, 3], id="Simple square padded by 2 all edges"),
pytest.param(
(3, 10), [1, 1, 2, 2], 4, [0, 0, 3, 6], id="Simple square padded by 4 beyond rows but within columns"
),
pytest.param(
(10, 10), [7, 7, 9, 9], 4, [3, 3, 10, 10], id="Simple square padded by 4 beyond bottom and right edges"
),
],
)
def test_pad_bounding_box(array_shape: tuple, bounding_box: list, pad_width: int, target: npt.NDArray) -> None:
"""Test of pad_bounding_box()."""
padded_box = disordered_tracing.pad_bounding_box(array_shape, bounding_box, pad_width)
assert padded_box == target
7 changes: 4 additions & 3 deletions topostats/tracing/disordered_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

LOGGER = logging.getLogger(LOGGER_NAME)

# pylint: disable=too-many-positional-arguments
# too-many-positional-arguments
# pylint: disable=R0917


class disorderedTrace: # pylint: disable=too-many-instance-attributes
Expand Down Expand Up @@ -526,7 +527,7 @@ def prep_arrays(
Returns
-------
Tuple
Returns a tuple of two dictionaries, each consisting of cropped arrays.
Returns a tuple of three dictionaries, the cropped images, cropped masks and bounding boxes.
"""
# Get bounding boxes for each grain
region_properties = skimage_measure.regionprops(labelled_grains_mask)
Expand Down Expand Up @@ -729,7 +730,7 @@ def pad_bounding_box(array_shape: tuple, bounding_box: list, pad_width: int) ->
Parameters
----------
array_shape : tuple
Shape of original image.
Shape of original image (row, columns).
bounding_box : list
List of coordinates 'min_row', 'min_col', 'max_row', 'max_col'.
pad_width : int
Expand Down

0 comments on commit 8b91408

Please sign in to comment.