Skip to content

Commit

Permalink
Merge 2129b92 into dbea039
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiamarcolini committed Aug 27, 2020
2 parents dbea039 + 2129b92 commit 428faea
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 37 deletions.
2 changes: 0 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# Raymond Hettinger’s “Beyond PEP 8” talk and highway patrol not stopping you
# if you drive < 5mph too fast. Disable E501 to avoid duplicate warnings.

exclude = src/histolab/filter.py # remove this line when filter is ok

max-line-length = 80
max-complexity = 12
select = E,F,W,C,B,B9
Expand Down
59 changes: 49 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
# Wire up travis
language: python
sudo: false

python:
- "3.6"
- "3.7"

before_install:
- sudo apt-get install openslide-tools
language: python # this works for Linux but is an error on macOS or Windows
jobs:
include:
- name: "Python 3.6 on Xenial Linux"
python: 3.6 # this works for Linux but is ignored on macOS or Windows
- name: "Python 3.7 on Xenial Linux"
python: 3.7 # this works for Linux but is ignored on macOS or Windows
- name: "Python 3.6.5 on macOS"
os: osx
osx_image: xcode9.4 # Python 3.7.4 running on macOS 10.14.4
language: shell # 'language: python' is an error on Travis CI macOS
before_install:
- brew update
- brew install openslide
- echo 'export PATH="/usr/local/Frameworks/Python.framework/Versions/Current/bin:$PATH"' >> /Users/travis/.bash_profile
- echo $PATH
- name: "Python 3.7.4 on macOS"
os: osx
osx_image: xcode11.2 # Python 3.7.4 running on macOS 10.14.4
language: shell # 'language: python' is an error on Travis CI macOS
before_install:
- brew install openslide
- echo 'export PATH="/usr/local/Frameworks/Python.framework/Versions/Current/bin:$PATH"' >> /Users/travis/.bash_profile
- echo $PATH
- name: "Python 3.6.8 on Windows"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- choco install python --version 3.6.8
- python -m pip install --upgrade pip
- wget https://github.com/openslide/openslide-winbuild/releases/download/v20171122/openslide-win64-20171122.zip -P /c/downloads
- 7z e /c/downloads/openslide-win64-20171122.zip -aoa
env: PATH=/c/Python36:/c/Python36/Scripts:/c/downloads/openslide-win64-20171122/bin:$PATH
- name: "Python 3.7 on Windows"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- choco install python --version 3.7
- python -m pip install --upgrade pip
- wget https://github.com/openslide/openslide-winbuild/releases/download/v20171122/openslide-win64-20171122.zip -P /c/downloads
- 7z e /c/downloads/openslide-win64-20171122.zip -aoa
env: PATH=/c/Python37:/c/Python37/Scripts:/c/downloads/openslide-win64-20171122/bin:$PATH

# command to install dependencies
install:
- pip install -e .[testing]
- pip install flake8
- pip3 install -e .[testing]
- pip3 install flake8

services:
- xvfb
Expand All @@ -30,4 +65,8 @@ after_success:
- coveralls

notifications:
slack: mpba:fBrjUWlUSa3XKeCA8zFsTFu2
slack: mpba:fBrjUWlUSa3XKeCA8zFsTFu2

addons:
apt:
packages: openslide-tools
4 changes: 2 additions & 2 deletions src/histolab/tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ def max_iter(self) -> int:
def max_iter(self, max_iter_: int = 1e4):
if max_iter_ < self.n_tiles:
raise ValueError(
f"The maximum number of iterations ({max_iter_}) must be grater than or "
f"equal to the maximum number of tiles ({self.n_tiles})."
f"The maximum number of iterations ({max_iter_}) must be grater than or"
f" equal to the maximum number of tiles ({self.n_tiles})."
)
self._valid_max_iter = max_iter_

Expand Down
14 changes: 9 additions & 5 deletions tests/integration/test_morphological_filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import numpy as np
import pytest

import histolab.filters.morphological_filters_functional as mof

Expand All @@ -15,28 +15,32 @@
3000,
True,
95,
"mask-arrays/diagnostic-slide-thumb-rgb1-hysteresis-threshold-remove-small-objects-mask",
"mask-arrays/diagnostic-slide-thumb-rgb1-hysteresis-threshold-remove-small-"
"objects-mask",
),
(
NPY.DIAGNOSTIC_SLIDE_THUMB_HSV_OTSU_THRESHOLD_MASK,
3000,
True,
95,
"mask-arrays/diagnostic-slide-thumb-hsv-otsu-threshold-remove-small-objects-mask",
"mask-arrays/diagnostic-slide-thumb-hsv-otsu-threshold-remove-small-objects"
"-mask",
),
(
NPY.DIAGNOSTIC_SLIDE_THUMB_HSV_OTSU_THRESHOLD_MASK,
3000,
False,
95,
"mask-arrays/diagnostic-slide-thumb-hsv-otsu-threshold-remove-small-objects2-mask",
"mask-arrays/diagnostic-slide-thumb-hsv-otsu-threshold-remove-small-objects"
"2-mask",
),
(
NPY.DIAGNOSTIC_SLIDE_THUMB_RGB1_HYSTERESIS_THRESHOLD_MASK,
1200,
True,
25,
"mask-arrays/diagnostic-slide-thumb-rgb1-hysteresis-threshold-remove-small-objects2-mask",
"mask-arrays/diagnostic-slide-thumb-rgb1-hysteresis-threshold-remove-small-"
"objects2-mask",
),
),
)
Expand Down
36 changes: 22 additions & 14 deletions tests/unit/test_slide.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding: utf-8

import errno
import math
import os
from collections import namedtuple
Expand Down Expand Up @@ -108,7 +109,7 @@ def it_knows_its_thumbnails_path(self, resampled_dims_):
"/foo/bar/myslide.svs",
"/foo/bar/myslide/processed",
(345, 111, 333, 444),
"/foo/bar/myslide/processed/thumbnails/myslide.png",
os.path.join("/foo/bar/myslide/processed", "thumbnails", "myslide.png"),
)
resampled_dims_.return_value = slide_dims
slide = Slide(slide_path, proc_path)
Expand Down Expand Up @@ -216,7 +217,8 @@ def or_it_raises_an_PIL_exception(self, tmpdir):

assert isinstance(err.value, PIL.UnidentifiedImageError)
assert (
str(err.value) == f"cannot identify image file '{os.path.join(slide_path)}'"
str(err.value) == "cannot identify image file "
f"{repr(os.path.join(slide_path))}"
)

def it_can_resample_itself(self, tmpdir, resampled_dims_):
Expand Down Expand Up @@ -444,7 +446,7 @@ def but_it_raises_error_when_it_doesnt_exist(self):
assert (
str(err.value)
== "Cannot display the slide thumbnail:[Errno 2] No such file or "
"directory: 'processed/thumbnails/b.png'"
f"directory: {repr(os.path.join('processed', 'thumbnails', 'b.png'))}"
)

def it_knows_its_level_dimensions(self, tmpdir):
Expand Down Expand Up @@ -508,25 +510,31 @@ def slide_ext_fixture(self, request):
"/foo/bar/myslide.svs",
"/foo/bar/myslide/processed",
(345, 111, 333, 444),
"/foo/bar/myslide/processed/myslide-22x-345x111-333x444.png",
os.path.join(
"/foo/bar/myslide/processed", "myslide-22x-345x111-333x444.png"
),
),
(
"/foo/bar/myslide2.svs",
"/foo/bar/myslide/processed",
(345, 111, None, None),
"/foo/bar/myslide/processed/myslide2-22x-345x111-NonexNone.png",
os.path.join(
"/foo/bar/myslide/processed", "myslide2-22x-345x111-NonexNone.png"
),
),
(
"/foo/bar/myslide2.svs",
"/foo/bar/myslide/processed",
(345, 111, 123, 123),
"/foo/bar/myslide/processed/myslide2-22x-345x111-123x123.png",
os.path.join(
"/foo/bar/myslide/processed", "myslide2-22x-345x111-123x123.png"
),
),
(
"/foo/bar/myslide2.svs",
"/foo/bar/myslide/processed",
(None, None, None, None),
"/foo/bar/myslide/processed/myslide2*.png",
os.path.join("/foo/bar/myslide/processed", "myslide2*.png"),
),
]
)
Expand All @@ -542,47 +550,47 @@ def scaled_img_path_fixture(self, request):
"/foo/bar/myslide.svs",
"processed",
64,
"/foo/bar/b/0/9/myslide-64x-245x123-145x99.png",
os.path.join("/foo/bar/b/0/9", "myslide-64x-245x123-145x99.png"),
),
(
(245, 123, 145, 99),
"/foo/bar/b/0/9",
"/foo/bar/myslide.svs",
"processed",
32,
"/foo/bar/b/0/9/myslide-32x-245x123-145x99.png",
os.path.join("/foo/bar/b/0/9", "myslide-32x-245x123-145x99.png"),
),
(
(None, None, None, None),
"/foo/bar/b/0/9",
"/foo/bar/myslide.svs",
"processed",
64,
"/foo/bar/b/0/9/myslide*.png",
os.path.join("/foo/bar/b/0/9", "myslide*.png"),
),
(
(None, 234, 192, None),
"/foo/bar/b/0/9",
"/foo/bar/myslide.svs",
"processed",
64,
"/foo/bar/b/0/9/myslide-64x-Nonex234-192xNone.png",
os.path.join("/foo/bar/b/0/9", "myslide-64x-Nonex234-192xNone.png"),
),
(
(123, 234, 192, None),
"/foo/bar/b/0/9",
"/foo/bar/myslide.svs",
"processed",
64,
"/foo/bar/b/0/9/myslide-64x-123x234-192xNone.png",
os.path.join("/foo/bar/b/0/9", "myslide-64x-123x234-192xNone.png"),
),
(
(None, None, 192, None),
"/foo/bar/b/0/9",
"/foo/bar/myslide.svs",
"processed",
64,
"/foo/bar/b/0/9/myslide-64x-NonexNone-192xNone.png",
os.path.join("/foo/bar/b/0/9", "myslide-64x-NonexNone-192xNone.png"),
),
]
)
Expand Down Expand Up @@ -706,7 +714,7 @@ def it_knows_its_slides(self, tmpdir):
slides = slideset.slides

assert isinstance(err.value, FileNotFoundError)
assert str(err.value) == "[Errno 2] No such file or directory: 'fake/path'"
assert err.value.errno == errno.ENOENT

def it_constructs_its_sequence_of_slides_to_help(self, request, Slide_, tmpdir):
slides_path = tmpdir.mkdir("mypath")
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/test_tiler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import os
from unittest.mock import call

Expand Down Expand Up @@ -68,7 +69,8 @@ def or_it_has_wrong_max_iter(self, request):
assert isinstance(err.value, ValueError)
assert (
str(err.value)
== "The maximum number of iterations (3) must be grater than or equal to the maximum number of tiles (10)."
== "The maximum number of iterations (3) must be grater than or equal to "
"the maximum number of tiles (10)."
)

def or_it_has_wrong_seed(self, request, tmpdir):
Expand Down Expand Up @@ -850,15 +852,16 @@ def it_can_save_report(self, request, tmpdir):
filenames = ["tile0.png", "tile1.png"]
random_scorer_ = instance_mock(request, RandomScorer)
score_tiler = ScoreTiler(random_scorer_, (10, 10), 2, 2)
report_ = ["filename,score\n", "tile0.png,0.8\n", "tile1.png,0.7\n"]
report_ = ["filename,score", "tile0.png,0.8", "tile1.png,0.7"]

score_tiler._save_report(
os.path.join(tmp_path_, "report.csv"), highest_score_tiles, filenames
)

assert os.path.exists(os.path.join(tmp_path_, "report.csv"))
with open(os.path.join(tmp_path_, "report.csv")) as f:
report = f.readlines()
with open(os.path.join(tmp_path_, "report.csv"), newline="") as f:
reader = csv.reader(f)
report = [",".join(row) for row in reader]
assert report == report_

def it_can_extract_score_tiles_and_save_report(self, request, tmpdir):
Expand Down

0 comments on commit 428faea

Please sign in to comment.