Skip to content

Commit

Permalink
tile 100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoarbitrio authored and alessiamarcolini committed Sep 5, 2020
1 parent 52d7992 commit 7b55a25
Showing 1 changed file with 42 additions and 22 deletions.
64 changes: 42 additions & 22 deletions tests/unit/test_tile.py
@@ -1,6 +1,8 @@
import numpy as np
import os

import pytest

import numpy as np
from histolab.filters.image_filters import Compose
from histolab.tile import Tile
from histolab.types import CoordinatePair
Expand All @@ -10,8 +12,8 @@
PILImageMock,
class_mock,
initializer_mock,
property_mock,
method_mock,
property_mock,
)


Expand Down Expand Up @@ -60,6 +62,24 @@ def it_knows_its_level(self):

assert level == 0

def it_can_save_the_tile_image(self, tmpdir):
tmp_path_ = os.path.join(tmpdir.mkdir("mydir"), "mytile.png")
_image = PILImageMock.DIMS_50X50_RGBA_COLOR_155_0_0
tile = Tile(_image, None, 0)

tile.save(tmp_path_)

assert os.path.exists(tmp_path_)

def and_it_can_save_the_tile_image_also_without_ext(self, tmpdir):
tmp_path_ = os.path.join(tmpdir.mkdir("mydir"), "mytile")
_image = PILImageMock.DIMS_50X50_RGBA_COLOR_155_0_0
tile = Tile(_image, None, 0)

tile.save(tmp_path_)

assert os.path.exists(tmp_path_ + ".png")

def it_knows_if_it_has_enough_tissue(
self,
has_enough_tissue_fixture,
Expand Down Expand Up @@ -159,26 +179,6 @@ def it_knows_its_tissue_mask(

assert tissue_mask.shape == (50, 50)

@pytest.fixture
def RgbToGrayscale_(self, request):
return class_mock(request, "histolab.filters.image_filters.RgbToGrayscale")

@pytest.fixture
def OtsuThreshold_(self, request):
return class_mock(request, "histolab.filters.image_filters.OtsuThreshold")

@pytest.fixture
def BinaryDilation_(self, request):
return class_mock(
request, "histolab.filters.morphological_filters.BinaryDilation"
)

@pytest.fixture
def BinaryFillHoles_(self, request):
return class_mock(
request, "histolab.filters.morphological_filters.BinaryFillHoles"
)

# fixtures -------------------------------------------------------

@pytest.fixture(
Expand Down Expand Up @@ -240,3 +240,23 @@ def _has_only_some_tissue(self, request):
@pytest.fixture
def _has_tissue_more_than_percent(self, request):
return method_mock(request, Tile, "_has_tissue_more_than_percent")

@pytest.fixture
def RgbToGrayscale_(self, request):
return class_mock(request, "histolab.filters.image_filters.RgbToGrayscale")

@pytest.fixture
def OtsuThreshold_(self, request):
return class_mock(request, "histolab.filters.image_filters.OtsuThreshold")

@pytest.fixture
def BinaryDilation_(self, request):
return class_mock(
request, "histolab.filters.morphological_filters.BinaryDilation"
)

@pytest.fixture
def BinaryFillHoles_(self, request):
return class_mock(
request, "histolab.filters.morphological_filters.BinaryFillHoles"
)

0 comments on commit 7b55a25

Please sign in to comment.