Skip to content
Snippets Groups Projects
Commit c628b1ad authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Implemented some unit tests

parent 3c3666b5
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ paths = {
'images': {
'inbound': root / 'images' / 'inbound',
'outbound': root / 'images' / 'outbound',
}
},
'ilastik' : {
'projects' : root / 'ilastik'
}
......
from pathlib import Path
root = Path('c:/Users/rhodes/projects/proj0015-model-server/resources')
paths = {
'czifile': root / 'testdata' / 'Selection--W0000--P0001-T0001.czi'
}
czifile_attr = {
'w': 1024,
'h': 1024,
'c': 4,
'z': 1,
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ class GenericImageFileAccessor(object):
class CziImageFileAccessor(GenericImageFileAccessor):
def __init__(self, fpath: Path):
super(CziImageFileAccessor).__init__(fpath)
super().__init__(fpath)
self.fpath = fpath
try:
cf = czifile.CziFile(fpath)
......
......@@ -2,7 +2,7 @@ from math import floor
import numpy as np
from image import GenericImageFileAccessor
from model_server.image import GenericImageFileAccessor
class Model(object):
def load(self):
......@@ -16,7 +16,7 @@ class Model(object):
class ImageToImageModel(Model): # receives an image and returns an image of the same size
def infer(self, img, channel=None) -> (np.ndarray, dict):
super(DummyImageToImageModel).infer(img, channel)
super().infer(img, channel)
class IlastikImageToImageModel(ImageToImageModel):
pass
......@@ -26,12 +26,12 @@ class DummyImageToImageModel(Model):
self.loaded = True
def infer(self, img, channel=None) -> (np.ndarray, dict):
super(DummyImageToImageModel).infer(img, channel)
super().infer(img, channel)
w = img.shape_dict['X']
h = img.shape_dict['Y']
result = np.zeros([h, w], dtype='uint8')
result[floor(0.25 * h) : floor(0.75 * h), floor(0.25 * w) : floor(0.75 * w)] = 255
return result
return (result, {'success': True})
class Error(Exception):
pass
......
......@@ -47,6 +47,7 @@ class Session(object):
self.logfile = create_session_log()
def register_inference(self, record):
# TODO: same this to file
self.manifest.append(record)
class Error(Exception):
......
......@@ -5,13 +5,13 @@ def validate_directory_exists(path):
class SharedImageDirectory(object):
def __init__(self, path): # create at session startup, validate
def __init__(self, path):
self.path = path
self.is_memory_mapped = False
if not validate_directory_exists(path):
raise InvalidDirectoryError(f'Invalid directory:\n{path}')
class InvalidDirectoryError(Exception):
pass
import unittest
from conf.testing import czifile_attr, paths
from model_server.image import CziImageFileAccessor
class TestCziImageFileAccess(unittest.TestCase):
def setUp(self) -> None:
pass
def test_czifile_is_correct_shape(self):
cf = CziImageFileAccessor(paths['czifile'])
self.assertEqual(cf.shape_dict['Y'], czifile_attr['h'])
self.assertEqual(cf.shape_dict['X'], czifile_attr['w'])
self.assertEqual(cf.chroma, czifile_attr['c'])
self.assertFalse(cf.is_3d)
\ No newline at end of file
import unittest
from conf.testing import paths
from model_server.image import CziImageFileAccessor
from model_server.model import DummyImageToImageModel
class TestCziImageFileAccess(unittest.TestCase):
def setUp(self) -> None:
self.cf = CziImageFileAccessor(paths['czifile'])
def test_czifile_is_correct_shape(self):
model = DummyImageToImageModel()
model.infer(self.cf, channel=1)
# TODO: check that result is a white rectangle
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment