Fixed bug : now test0001.bash fails if the python script fails.
This allows to now detect if the test succeeds or not. Also turned test_preprocessing into a proper unit test. This test is now much cleaner, as preprocessing.py does no longer require ij related code.
This commit is contained in:
parent
d9b8605dc2
commit
fe389f7897
|
@ -2,8 +2,6 @@
|
|||
|
||||
from catalog import ImageCatalog, Sequence
|
||||
from imageengine import IImageEngine
|
||||
from imagej.ijimageengine import IJImageEngine, IJImage
|
||||
|
||||
|
||||
class WhiteEstimator(object):
|
||||
|
||||
|
@ -260,18 +258,3 @@ def find_white_reference_image(white_estimate, white_z_stack):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def test_preprocessing(raw_images_root_path):
|
||||
"""Test preprocessing."""
|
||||
IImageEngine.set_instance(IJImageEngine())
|
||||
catalog = ImageCatalog(raw_images_root_path)
|
||||
sequence = catalog.sequences['res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos2']
|
||||
white_estimator = WhiteEstimator(open_size=75, close_size=75, average_size=75)
|
||||
white_estimate = white_estimator.estimate_white([sequence], ['DM300_327-353_fluo'])
|
||||
# find_white_reference_image(white_estimate, sequence.get_white())
|
||||
print(white_estimate)
|
||||
IImageEngine.get_instance().save_as_tiff(white_estimate, './white_estimate.tiff')
|
||||
print('end')
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_preprocessing(raw_images_root_path='/Users/graffy/ownCloud/ipr/lipase/raw-images')
|
||||
|
|
|
@ -9,12 +9,16 @@ case "$(uname)" in
|
|||
;;
|
||||
'Darwin')
|
||||
FIJI_EXE_PATH='/Applications/Fiji.app/Contents/MacOS/ImageJ-macosx'
|
||||
RAW_IMAGES_ROOT_PATH='/Users/graffy/ownCloud/ipr/lipase/raw-images'
|
||||
RAW_IMAGES_ROOT_PATH='/Users/graffy/work/lipase/raw-images'
|
||||
;;
|
||||
*)
|
||||
echo "unhandled openating system : $(uname)"
|
||||
echo "unhandled operating system : $(uname)"
|
||||
exit 1
|
||||
esac
|
||||
"$FIJI_EXE_PATH" --ij2 --headless --run './tests/test0001.py' "lipase_src_root_path='$LIPASE_SRC_ROOT_PATH',raw_images_root_path='$RAW_IMAGES_ROOT_PATH'"
|
||||
"$FIJI_EXE_PATH" --ij2 --headless --run './tests/test0001.py' "raw_images_root_path='$RAW_IMAGES_ROOT_PATH'"
|
||||
# on macosx : /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run './test0001.py'
|
||||
# /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run './tests/test0001.py' "lipase_src_root_path='$(pwd)',raw_images_root_path='/Users/graffy/ownCloud/ipr/lipase/raw-images'"
|
||||
ERROR_CODE=$?
|
||||
echo "Fiji 's return code : $ERROR_CODE"
|
||||
ERROR_CODE=$(cat '/tmp/test_result.txt')
|
||||
exit $ERROR_CODE
|
|
@ -3,23 +3,56 @@
|
|||
# # note: fiji's jython doesn't support encoding keyword
|
||||
|
||||
# https://imagej.net/Scripting_Headless
|
||||
#@ String lipase_src_root_path
|
||||
#@ String raw_images_root_path
|
||||
|
||||
# String(label="Please enter your name",description="Name field") name
|
||||
# OUTPUT String greeting
|
||||
import unittest # unittest2 doesn't exist in fiji
|
||||
import sys
|
||||
print('python version %s' % sys.version) # prints python version
|
||||
from lipase.catalog import ImageCatalog, Sequence
|
||||
from lipase.imageengine import IImageEngine
|
||||
from lipase.imagej.ijimageengine import IJImageEngine, IJImage
|
||||
from lipase.preprocessing import WhiteEstimator
|
||||
|
||||
# it is necassary to add lipase's root path to the path if run from fiji as script otherwise jython fails to find lipase's modules such as catalog
|
||||
sys.path.append(lipase_src_root_path) # pylint: disable=undefined-variable
|
||||
class TestLipase(unittest.TestCase):
|
||||
|
||||
# from lipase import Lipase, ImageLogger
|
||||
from preprocessing import test_preprocessing # noqa: E402 pylint: disable=import-error,wrong-import-position
|
||||
RAW_IMAGES_ROOT_PATH = raw_images_root_path # eg '/Users/graffy/ownCloud/ipr/lipase/raw-images' pylint: disable=undefined-variable
|
||||
|
||||
# we need to know if the test succeeded or not https://stackoverflow.com/questions/4414234/getting-pythons-unittest-results-in-a-teardown-method
|
||||
# CURRENT_RESULT = None # holds last result object passed to run method
|
||||
|
||||
def setUp(self):
|
||||
print("initializing TestLipase instance")
|
||||
IImageEngine.set_instance(IJImageEngine())
|
||||
self.catalog = ImageCatalog(self.RAW_IMAGES_ROOT_PATH)
|
||||
|
||||
def tearDown(self):
|
||||
print("uninitializing TestLipase instance")
|
||||
self.catalog = None
|
||||
|
||||
|
||||
|
||||
def test_estimate_white(self):
|
||||
sequence = self.catalog.sequences['res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos2']
|
||||
white_estimator = WhiteEstimator(open_size=75, close_size=75, average_size=75)
|
||||
white_estimate = white_estimator.estimate_white([sequence], ['DM300_327-353_fluo'])
|
||||
# find_white_reference_image(white_estimate, sequence.get_white())
|
||||
print(white_estimate)
|
||||
IImageEngine.get_instance().save_as_tiff(white_estimate, './white_estimate.tiff')
|
||||
# assert False, "hellooooo"
|
||||
print('end of test_estimate_white')
|
||||
|
||||
|
||||
def run_script():
|
||||
test_preprocessing(raw_images_root_path) # eg '/Users/graffy/ownCloud/ipr/lipase/raw-images' pylint: disable=undefined-variable
|
||||
|
||||
# unittest.main() # this would result in : ImportError: No module named __main__
|
||||
# solution from : https://discourse.mcneel.com/t/using-unittest-in-rhino-python-not-possible/15364
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestLipase)
|
||||
stream = sys.stdout # by default it's sys.stderr, which doesn't appear in imagej's output
|
||||
test_result = unittest.TextTestRunner(stream=stream, verbosity=2).run(suite)
|
||||
print('test_result : %s' % test_result)
|
||||
# store summary of the result in a file so that the caller of imagej can detect that this python script failed (imagej seems to always return error code 0, regardless the error returned by the python script it executes : even sys.exit(1) doesn't change this)
|
||||
with open('/tmp/test_result.txt', 'w') as f:
|
||||
f.write('%d' % {True: 0, False: 1}[test_result.wasSuccessful()])
|
||||
print('end of run_script')
|
||||
|
||||
# note : when launched from fiji, __name__ doesn't have the value "__main__", as when launched from python
|
||||
run_script()
|
||||
|
|
Loading…
Reference in New Issue