def test(self):    
        # Define the files we'll be making    
        testProjectName = 'test_project.ilp'
        # Clean up: Remove the test data files we created last time (just in case)
        for f in [testProjectName]:
            try:
                os.remove(f)
            except:
                pass
    
        # Create an empty project
        with h5py.File(testProjectName) as testProject:
            testProject.create_dataset("ilastikVersion", data=b"1.0.0")
            
            # Create an operator to work with and give it some input
            g = Graph()
            op = OpMockPixelClassifier(graph=g)
            operatorToSave = op
            serializer = PixelClassificationSerializer(operatorToSave, 'PixelClassificationTest')
            
            op.LabelInputs.resize( 1 )
    
            # Create some labels
            labeldata = numpy.zeros(op.dataShape)
            labeldata[:,:,0:5,:,:] = 1
            labeldata[:,:,50:60,:] = 2
    
            # Slice them into our operator
            op.LabelInputs[0][0:1, 0:10, 0:5,   0:100, 0:1] = labeldata[:,:,0:5,:,:]
            op.LabelInputs[0][0:1, 0:10, 50:60, 0:100, 0:1] = labeldata[:,:,50:60,:,:]

            # change label names and colors
            op.LabelNames.setValue( ["Label1", "Label2"] )
            op.LabelColors.setValue( [(255,30,30), (30,255,30)] )
            op.PmapColors.setValue( [(255,30,30), (30,255,30)] )
            
            # Simulate the predictions changing by setting the prediction output dirty
            op.PredictionProbabilities[0].setDirty(slice(None))
    
            # Serialize!
            serializer.serializeToHdf5(testProject, testProjectName)
                
            # Deserialize into a fresh operator
            operatorToLoad = OpMockPixelClassifier(graph=g)
            deserializer = PixelClassificationSerializer(operatorToLoad, 'PixelClassificationTest')
            deserializer.deserializeFromHdf5(testProject, testProjectName)
    
            # Did the data go in and out of the file without problems?
            assert len(operatorToLoad.LabelImages) == 1
            assert (operatorToSave.LabelImages[0][...].wait() == operatorToLoad.LabelImages[0][...].wait()).all()
            assert (operatorToSave.LabelImages[0][...].wait() == labeldata[...]).all()

            assert operatorToSave.LabelNames.value == operatorToLoad.LabelNames.value, \
                "{} != {}".format( operatorToSave.LabelNames.value, operatorToLoad.LabelNames.value )
            assert (numpy.array(operatorToSave.LabelColors.value) == numpy.array(operatorToLoad.LabelColors.value)).all()
            assert (numpy.array(operatorToSave.PmapColors.value) == numpy.array(operatorToLoad.PmapColors.value)).all()
        
        os.remove(testProjectName)
    def test(self):    
        # Define the files we'll be making    
        testProjectName = 'test_project.ilp'
        # Clean up: Remove the test data files we created last time (just in case)
        for f in [testProjectName]:
            try:
                os.remove(f)
            except:
                pass
    
        # Create an empty project
        with h5py.File(testProjectName) as testProject:
            testProject.create_dataset("ilastikVersion", data="1.0.0")
            
            # Create an operator to work with and give it some input
            g = Graph()
            op = OpMockPixelClassifier(graph=g)
            operatorToSave = op
            serializer = PixelClassificationSerializer(operatorToSave, 'PixelClassificationTest')
            
            op.LabelInputs.resize( 1 )
    
            # Create some labels
            labeldata = numpy.zeros(op.dataShape)
            labeldata[:,:,0:5,:,:] = 1
            labeldata[:,:,50:60,:] = 2
    
            # Slice them into our operator
            op.LabelInputs[0][0:1, 0:10, 0:5,   0:100, 0:1] = labeldata[:,:,0:5,:,:]
            op.LabelInputs[0][0:1, 0:10, 50:60, 0:100, 0:1] = labeldata[:,:,50:60,:,:]

            # change label names and colors
            op.LabelNames.setValue( ["Label1", "Label2"] )
            op.LabelColors.setValue( [(255,30,30), (30,255,30)] )
            op.PmapColors.setValue( [(255,30,30), (30,255,30)] )
            
            # Simulate the predictions changing by setting the prediction output dirty
            op.PredictionProbabilities[0].setDirty(slice(None))
    
            # Serialize!
            serializer.serializeToHdf5(testProject, testProjectName)
                
            # Deserialize into a fresh operator
            operatorToLoad = OpMockPixelClassifier(graph=g)
            deserializer = PixelClassificationSerializer(operatorToLoad, 'PixelClassificationTest')
            deserializer.deserializeFromHdf5(testProject, testProjectName)
    
            # Did the data go in and out of the file without problems?
            assert len(operatorToLoad.LabelImages) == 1
            assert (operatorToSave.LabelImages[0][...].wait() == operatorToLoad.LabelImages[0][...].wait()).all()
            assert (operatorToSave.LabelImages[0][...].wait() == labeldata[...]).all()

            assert operatorToSave.LabelNames.value == operatorToLoad.LabelNames.value
            assert (numpy.array(operatorToSave.LabelColors.value) == numpy.array(operatorToLoad.LabelColors.value)).all()
            assert (numpy.array(operatorToSave.PmapColors.value) == numpy.array(operatorToLoad.PmapColors.value)).all()
        
        os.remove(testProjectName)
 def test(self):    
     # Define the files we'll be making    
     testProjectName = 'test_project.ilp'
     # Clean up: Remove the test data files we created last time (just in case)
     for f in [testProjectName]:
         try:
             os.remove(f)
         except:
             pass
 
     # Create an empty project
     with h5py.File(testProjectName) as testProject:
         testProject.create_dataset("ilastikVersion", data=0.6)
         
         # Create an operator to work with and give it some input
         g = Graph()
         op = OpMockPixelClassifier(graph=g)
         operatorToSave = op
         serializer = PixelClassificationSerializer(operatorToSave, 'PixelClassificationTest')
         
         op.LabelInputs.resize( 1 )
 
         # Create some labels
         labeldata = numpy.zeros(op.dataShape)
         labeldata[:,:,0:5,:,:] = 1
         labeldata[:,:,50:60,:] = 2
 
         # Slice them into our operator
         op.LabelInputs[0][0:1, 0:10, 0:5,   0:100, 0:1] = labeldata[:,:,0:5,:,:]
         op.LabelInputs[0][0:1, 0:10, 50:60, 0:100, 0:1] = labeldata[:,:,50:60,:,:]
         
         # Simulate the predictions changing by setting the prediction output dirty
         op.PredictionProbabilities[0].setDirty(slice(None))
 
         # Enable prediction storage
         serializer.predictionStorageEnabled = True
             
         # Serialize!
         serializer.serializeToHdf5(testProject, testProjectName)
 
         # Check that the prediction data was written to the file
         assert (testProject['PixelClassificationTest/Predictions/predictions0000'][...] == op.PredictionProbabilities[0][...].wait()).all()
         
         # Deserialize into a fresh operator
         operatorToLoad = OpMockPixelClassifier(graph=g)
         deserializer = PixelClassificationSerializer(operatorToLoad, 'PixelClassificationTest')
         deserializer.deserializeFromHdf5(testProject, testProjectName)
 
         # Did the data go in and out of the file without problems?
         assert len(operatorToLoad.LabelImages) == 1
         assert (operatorToSave.LabelImages[0][...].wait() == operatorToLoad.LabelImages[0][...].wait()).all()
         assert (operatorToSave.LabelImages[0][...].wait() == labeldata[...]).all()
     
     os.remove(testProjectName)