Created
July 5, 2023 14:42
-
-
Save manthey/39f5f37a023e9cd63bcd9d6f473db3f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import tempfile | |
from pathlib import Path | |
from .datastore import datastore | |
class TestNucleiDetection: | |
def _runTest(self, args): | |
from histomicstk.cli.NucleiDetection import NucleiDetection | |
from histomicstk.cli.utils import CLIArgumentParser | |
parentdir = Path(NucleiDetection.__file__).parent | |
xmlfile = parentdir / 'NucleiDetection.xml' | |
# In our tox environment, the xml files aren't always copied | |
while not xmlfile.exists(): | |
if parentdir.parent == parentdir: | |
break | |
parentdir = parentdir.parent | |
xmlfile = parentdir / 'histomicstk/cli/NucleiDetection/NucleiDetection.xml' | |
with tempfile.TemporaryDirectory() as tmpdirname: | |
outpath = os.path.join(tmpdirname, 'result.json') | |
NucleiDetection.main(CLIArgumentParser(xmlfile).parse_args( | |
args + [outpath, '--scheduler=multithreading'])) | |
return json.load(open(outpath)) | |
def test_rgb_mag(self): | |
src = datastore.fetch('tcgaextract_rgbmag.tiff') | |
annot = self._runTest([src]) | |
assert 2500 < len(annot['elements']) < 3000 | |
def test_rgb_mag_roi(self): | |
src = datastore.fetch('tcgaextract_rgbmag.tiff') | |
annot = self._runTest([src, '--analysis_roi=1,1,3998,2998']) | |
assert 2500 < len(annot['elements']) < 3000 | |
def test_inverted_hematoxylin_mag(self): | |
src = datastore.fetch('tcgaextract_ihergb_labeledmag.tiff') | |
annot = self._runTest([src]) | |
assert 2500 < len(annot['elements']) < 3000 | |
def test_hematoxylin_mag(self): | |
src = datastore.fetch('tcgaextract_ihergb_labeledmag.tiff') | |
annot = self._runTest([src, '--frame=1', '--output_form=No']) | |
assert 2500 < len(annot['elements']) < 3000 | |
def test_compositied_mag(self): | |
src = datastore.fetch('tcgaextract_ihergb_labeledmag.tiff') | |
annot = self._runTest([src, '--style', json.dumps({ | |
'bands': [ | |
{'palette': '#FF0000', 'framedelta': 3}, | |
{'palette': '#00FF00', 'framedelta': 4}, | |
{'palette': '#0000FF', 'framedelta': 5} | |
] | |
})]) | |
assert 2500 < len(annot['elements']) < 3000 | |
# We could add similar tests with the files that don't have magnification | |
# set, and add similar tests where we pass an ROI that is the whole image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of multiple tests for each file and combination, you make fewer tests and use
pytest.mark.parameterize
: