def test_external_image_selection(self): d = tempfile.mkdtemp(prefix='external_image', dir='.') self.general_setup(d) os.mkdir(os.path.join(d, 'test_projects')) os.mkdir(os.path.join(d, 'images')) hdf5dir = os.path.join(d, 'hdf5') def mysetup(): os.mkdir(hdf5dir) with open(os.path.join(hdf5dir, 'test_project1.hdf5'), 'w') as fp: fp.write('foo') mysetup() self.addFileToRemove(d, preemptive=False) be = batch_project.BatchExecutor(os.path.join(d, 'test_projects'), workdir=d, global_variables={'image_dir': os.path.join(d, 'images'), 'hdf5dir': hdf5dir, 'results': os.path.join(d, 'images')}) batch_project.loadCustomFunctions() batchProject = batch_project.loadJSONGraph( self.locateFile('tests/specifications/external_image_batch_process.json')) saveAsPng(self.locateFile('tests/images/test_project1.jpg'), os.path.join(d, 'images', 'test_project1.png'.format(d))) with open(os.path.join(d, 'images', 'arguments.csv'), 'w') as fp: fp.write('test_project1.png,no,16') dir, name = be.runProjectLocally(batchProject) be.finish(remove_logs=True) self.assertTrue(dir is not None) self.assertTrue(os.path.exists(os.path.join(hdf5dir, 'test_project1.hdf5')))
def createExecutor(self, prefix,skipValidation=False, loglevel=50, setup=False,global_variables={}): d = tempfile.mkdtemp(prefix=prefix, dir='.') os.mkdir(os.path.join(d,'test_projects')) if setup: self.general_setup(d) be = batch_project.BatchExecutor(os.path.join(d,'test_projects'), workdir=d, loglevel=loglevel, skipValidation=skipValidation, global_variables=global_variables) self.addFileToRemove(d) return be
def test_image_selection(self): self.general_setup() batch_project.loadCustomFunctions() batchProject = batch_project.loadJSONGraph( self.locateFile( 'tests/specifications/simple_image_selector_plugin.json')) be = batch_project.BatchExecutor( 'test_projects', skipValidation=True, global_variables={'image_dir': self.locateFile('tests/images')}) dir, name = be.runProjectLocally(batchProject) be.finish() self.assertTrue(dir is not None)
def test_validation(self): self.general_setup() manager = plugins.loadPlugins() PluginDeferCaller(manager.getBroker()) batchProject = batch_project.loadJSONGraph( self.locateFile( 'tests/specifications/batch_validation_process.json')) be = batch_project.BatchExecutor( 'test_projects', global_variables={'image_dir': self.locateFile('tests/images')}) dir, name = be.runProjectLocally(batchProject) be.finish() self.assertTrue(dir is None) plugins.PluginCaller(manager.getBroker())
def test_external_image_selection(self): self.addFileToRemove('imageset.txt', preemptive=True) with open('imageset.txt', 'w') as fp: fp.writelines([ filename + os.linesep for filename in os.listdir(self.locateFile('tests/images')) if not filename.startswith('test_project1') ]) if os.path.exists('results'): shutil.rmtree('results') if os.path.exists('test_projects'): shutil.rmtree('test_projects') os.mkdir('test_projects') os.mkdir('test_projects/hdf5') with open('test_projects/hdf5/test_project1.hdf5', 'w') as fp: fp.write('foo') be = batch_project.BatchExecutor('test_projects', global_variables={ 'image_dir': self.locateFile('tests/images'), 'hdf5dir': 'test_projects/hdf5' }) batch_project.loadCustomFunctions() batchProject = batch_project.loadJSONGraph( self.locateFile( 'tests/specifications/external_image_batch_process.json')) self.addFileToRemove('results', preemptive=True) self.addFileToRemove('test_projects', preemptive=False) os.mkdir('results') saveAsPng(self.locateFile('tests/images/test_project1.jpg'), 'results/test_project1.png') with open('results/arguments.csv', 'w') as fp: fp.write('test_project1.png,no,16') dir, name = be.runProjectLocally(batchProject) be.finish() self.assertTrue(dir is not None) self.assertTrue( os.path.exists('test_projects/test_project1/test_project1.hdf5'))