From 13eb92c76ee2facb0938835adc2bfff62141c932 Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Fri, 10 Apr 2020 13:26:05 +0200 Subject: [PATCH] allows the user to choose the location of the tests output data This prevents pollution of git repository with temporary files and is done via a makefile variable TESTS_OUTPUT_DATA_PATH. --- Jenkinsfile | 2 +- Makefile | 6 ++++-- tests/improc_tests.py | 4 +++- tests/test0001.py | 7 +++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e9e6852..29e36a9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { } stage('Testing the package...') { steps { - sh 'make FIJI_ROOT_PATH=$(pwd)/Fiji.app RAW_IMAGES_ROOT_PATH=/opt/ipr/cluster/work.global/graffy/jenkins-store/lipase/raw-images test' + sh 'make FIJI_ROOT_PATH=$(pwd)/Fiji.app RAW_IMAGES_ROOT_PATH=/opt/ipr/cluster/work.global/graffy/jenkins-store/lipase/raw-images TESTS_OUTPUT_DATA_PATH=$TMP/$(whoami)/$JOB_NAME test' } } stage('Building documentation...') { diff --git a/Makefile b/Makefile index 3b78b6a..f76b2f5 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ FIJI_ROOT_PATH:=~/soft/Fiji.app FIJI_EXE_PATH=$(FIJI_ROOT_PATH)/ImageJ-linux64 # RAW_IMAGES_ROOT_PATH:='/opt/ipr/cluster/work.global/graffy/jenkins-store/lipase/raw-images' RAW_IMAGES_ROOT_PATH:=$(shell echo ~/work/lipase/raw-images) +TESTS_OUTPUT_DATA_PATH:=$(shell echo ~/work/lipase/tmp) LIB_SRC_FILES=$(shell find ./src/lipase -name "*.py") PLUGINS_SRC_FILES=$(shell find ./src/ij-plugins -name "*.py") LIPASE_VERSION=1.01 @@ -89,7 +90,8 @@ test0001: install # 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'" echo 2 > '/tmp/test_result.txt' ; \ - $(FIJI_EXE_PATH) --ij2 --headless --run './tests/test0001.py' "raw_images_root_path='$(RAW_IMAGES_ROOT_PATH)'" ; \ + mkdir -p $(TESTS_OUTPUT_DATA_PATH) + $(FIJI_EXE_PATH) --ij2 --headless --run './tests/test0001.py' "raw_images_root_path='$(RAW_IMAGES_ROOT_PATH)',tests_output_data_path='$(TESTS_OUTPUT_DATA_PATH)'" ; \ ERROR_CODE=$$? ; \ echo "Fiji 's return code : $$ERROR_CODE" ; \ ERROR_CODE=$$(cat '/tmp/test_result.txt') ; \ @@ -99,7 +101,7 @@ test0001: install .PHONY: test0001 imgproc_tests: install echo 2 > '/tmp/test_result.txt' ; \ - $(FIJI_EXE_PATH) --ij2 --headless --run './tests/improc_tests.py' ; \ + $(FIJI_EXE_PATH) --ij2 --headless --run './tests/improc_tests.py' "tests_output_data_path='$(TESTS_OUTPUT_DATA_PATH)'" ; \ ERROR_CODE=$$? ; \ echo "Fiji 's return code : $$ERROR_CODE" ; \ ERROR_CODE=$$(cat '/tmp/test_result.txt') ; \ diff --git a/tests/improc_tests.py b/tests/improc_tests.py index df31a47..55bb75b 100644 --- a/tests/improc_tests.py +++ b/tests/improc_tests.py @@ -3,6 +3,7 @@ # # note: fiji's jython doesn't support encoding keyword # https://imagej.net/Scripting_Headless +#@ String tests_output_data_path import unittest # unittest2 doesn't exist in fiji import sys @@ -14,10 +15,11 @@ class ImProcTester(unittest.TestCase): # 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 + TESTS_OUTPUT_DATA_PATH = tests_output_data_path # eg '/tmp/lipase/tests-output-data' pylint: disable=undefined-variable def setUp(self): print("initializing ImProcTester instance") - IImageEngine.set_instance(IJImageEngine(debugger=FileBasedDebugger('./debug-images'))) + IImageEngine.set_instance(IJImageEngine(debugger=FileBasedDebugger('%s/debug-images' % self.TESTS_OUTPUT_DATA_PATH))) def tearDown(self): print("uninitializing ImProcTester instance") diff --git a/tests/test0001.py b/tests/test0001.py index 64f8f87..6ff9b83 100644 --- a/tests/test0001.py +++ b/tests/test0001.py @@ -4,6 +4,8 @@ # https://imagej.net/Scripting_Headless #@ String raw_images_root_path +#@ String tests_output_data_path + import unittest # unittest2 doesn't exist in fiji import sys @@ -23,13 +25,14 @@ from lipase.imagej.hdf5serializer import save_hdf5_file class TestLipase(unittest.TestCase): RAW_IMAGES_ROOT_PATH = raw_images_root_path # eg '/Users/graffy/ownCloud/ipr/lipase/raw-images' pylint: disable=undefined-variable + TESTS_OUTPUT_DATA_PATH = tests_output_data_path # eg '/tmp/lipase/tests-output-data' 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(debugger=FileBasedDebugger('./debug-images'))) + IImageEngine.set_instance(IJImageEngine(debugger=FileBasedDebugger('%s/debug-images' % self.TESTS_OUTPUT_DATA_PATH))) self.catalog = ImageCatalog(self.RAW_IMAGES_ROOT_PATH) def tearDown(self): @@ -102,7 +105,7 @@ class TestLipase(unittest.TestCase): background_estimator = EmptyFrameBackgroundEstimator(empty_frame_index=39) processor = GlobulesAreaEstimator(background_estimator=background_estimator, particle_threshold=2000.0) results = processor.detect_particles(visible_traps_sequence) - save_hdf5_file('results.h5', results) + save_hdf5_file('%s/results.h5' % self.TESTS_OUTPUT_DATA_PATH, results) # results file could be checked with "h5dump --xml ./lipase.git/results.h5" first_frame_measured_ratio = results['globules_area_ratio'][(0,)] first_frame_expected_ratio = 0.008