def test_generateCommandLine(self): edPlugin = self.getPlugin() strInputXML = EDUtilsFile.readFile(os.path.join(self.strDataPath, "XSDataInputAutoPROC_reference.xml")) xsDataInput = XSDataInputAutoPROC.parseString(strInputXML) strCommandLine = edPlugin.generateCommandLine(xsDataInput) print(strCommandLine) EDAssert.equal("-B -xml -I /scisoft/pxsoft/data/AUTO_PROCESSING/id29/20130301/RAW_DATA/GaelleB/xtal5 -Id 1088454,/scisoft/pxsoft/data/AUTO_PROCESSING/id29/20130301/RAW_DATA/GaelleB/xtal5,xtal5w1_1_####.cbf,1,100 -R 5.0 2.0 -ANO", strCommandLine, "Reference data input")
def testGenerateMosflmScriptName(self): """ This method tests the generateMosflmScriptName method of the Labelit plugin. """ edPluginLabelitv10 = self.createPlugin() EDAssert.equal("integration01.csh", edPluginLabelitv10.generateMosflmScriptName(1)) EDAssert.equal("integration10.csh", edPluginLabelitv10.generateMosflmScriptName(10))
def testGetOutputDataFromDNATableFile(self): edPluginRdfit = self.createPlugin() strPathToTableFile = os.path.join(self.strDataPath, "rdfit.xml") xsDataResultRdfit = edPluginRdfit.getOutputDataFromDNATableFile(strPathToTableFile) strPathToReference = os.path.join(self.strDataPath, "XSDataResultRdfit_reference.xml") xsDataResultRdfitReference = XSDataResultRdfit.parseFile(strPathToReference) EDAssert.equal(xsDataResultRdfitReference.marshal(), xsDataResultRdfit.marshal(), "Test parsing result 'DNA' xml file")
def testExecute(self): EDTestCasePluginExecuteControlCharacterisationv1_4.testExecute(self) edPlugin = self.getPlugin() strStatusMessage = None if edPlugin.hasDataOutput("statusMessage"): strStatusMessage = edPlugin.getDataOutput( "statusMessage")[0].getValue() EDAssert.equal( True, strStatusMessage.find("Strategy calculation FAILURE") != -1, "Status message contains 'Strategy calculation FAILURE'")
def testExecute(self): self.run() plugin = self.getPlugin() EDVerbose.DEBUG('Checking error messages...') EDAssert.equal(self.m_iNoErrorMessages, self.getErrorMessages().getNumberObjects()) EDVerbose.DEBUG('Checking warning messages...') EDAssert.equal(self.m_iNoWarningMessages, self.getWarningMessages().getNumberObjects())
def unitTestSetGetData(self): """ check the status after a job creation """ EDVerbose.DEBUG("EDTestCaseEDJob.unitTestSetGetData") edJob = EDJob(self.strPluginName) edJob.setDataInput(self.strXmlInput) EDAssert.equal(self.strXmlInput, edJob.getDataInput().strip(), "Data Input is correctly set") EDAssert.equal("uninitialized", edJob.getStatus(), "Job %s is still ''uninitialized''" % edJob.getJobId())
def testCreatePyarchHtmlDirectoryPath(self): strTestDataDir = self.getPluginTestsDataHome() strTestFile = os.path.join(strTestDataDir, "EDHandlerESRFPyarchv1_0", "XSDataCollection_reference.xml") strXml = self.readAndParseFile(strTestFile) xsDataCollection = XSDataCollection.parseString(strXml) strPyarchHtmlDirectoryPath = EDHandlerESRFPyarchv1_0.createPyarchHtmlDirectoryPath( xsDataCollection) # print strPyarchHtmlDirectoryPath strReferencePath = "/data/pyarch/2016/id30b/opid30b/20161214/RAW_DATA/Magda/Test_x1_2_dnafiles" EDAssert.equal(strReferencePath, strPyarchHtmlDirectoryPath, "Correct pyarch path")
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecMeasureOffsetv1_0.preProcess") sdi = self.dataInput images = sdi.image arrays = sdi.array if len(images) == 2: self.npaIm1 = numpy.array(EDUtilsArray.getArray(images[0])) self.npaIm2 = numpy.array(EDUtilsArray.getArray(images[1])) elif len(arrays) == 2: self.npaIm1 = EDUtilsArray.xsDataToArray(arrays[0]) self.npaIm2 = EDUtilsArray.xsDataToArray(arrays[1]) else: strError = "EDPluginExecMeasureOffsetv1_0.preProcess: You should either provide two images or two arrays, but I got: %s" % sdi.marshal( )[:1000] self.ERROR(strError) self.setFailure() raise RuntimeError(strError) crop = sdi.cropBorders if len(crop) > 1: self.tCrop = tuple([i.value for i in crop]) elif len(crop) == 1: self.tCrop = (crop[0].value, crop[0].value) center = sdi.center if len(center) > 1: self.tCenter = tuple([i.value for i in center]) elif len(center) == 1: self.tCenter = (center[0].value, center[0].value) width = sdi.width if len(width) > 1: self.tWidth = tuple([i.value for i in width]) elif len(width) == 1: self.tWidth = (width[0].value, width[0].value) smooth = sdi.smoothBorders if len(smooth) == 2: self.tSmooth = (smooth[0].value, smooth[1].value) elif len(smooth) == 1: self.tSmooth = (smooth[0].value, smooth[0].value) if sdi.backgroundSubtraction is not None: self.bBackgroundsubtraction = (sdi.backgroundSubtraction.value in [1, True, "true"]) if sdi.sobelFilter is not None: self.sobel = (sdi.sobelFilter in [1, True, "true"]) EDAssert.equal(self.npaIm1.shape, self.npaIm2.shape, "Images have the same size")
def testPopulateXSDataInputSPDCake(self): edPluginControlID11 = self.createPlugin() xsDataInputSPDCake = edPluginControlID11.populateXSDataInputSPDCake( self.dictID11Reference) strDataPath = self.getPluginTestsDataHome() strReferenceFile = "XSDataInputSPDCake_fromDict.xml" strPath = os.path.join(strDataPath, strReferenceFile) xsDataInputSPDCakeReference = XSDataInputSPDCake.parseString( self.readAndParseFile(strPath)) xsDataInputSPDCakeReference.setDeleteCorImg( XSDataBoolean(not (EDVerbose.isVerboseDebug()))) EDAssert.equal(xsDataInputSPDCakeReference.marshal(), xsDataInputSPDCake.marshal())
def unitTestXsdToArray(self): """ test the execution of xsDataToArray static method """ EDVerbose.DEBUG("EDTestCaseEDUtilsArray.unitTestXsdToArray") if numpy is not None: EDAssert.arraySimilar(self.arrayNumpy, EDUtilsArray.xsDataToArray(self.xsDataArrayNumpy, _bForceNoNumpy=False), _strComment="Array are the same (Numpy used)") else: EDAssert.equal(self.arrayNoNumpy, EDUtilsArray.xsDataToArray(self.xsDataArrayNumpy, _bCheckMd5sum=True, _bForceNoNumpy=False), "Array are the same (no Numpy available)")
def testStaticEDConfiguration(self): # This test make sure that changing an instatiation of EDConfiguration does not change the # corresponding plugin configuration for EDConfigurationStatic strPathToTestConfigFile = os.path.join( self.strDataPath, "XSConfiguration_testNonStatic.xml") edConfiguration = EDConfiguration(strPathToTestConfigFile) strParam1 = edConfiguration.getStringValue("EDPluginTestPluginFactory", "testItemName") EDUtilsPath.setEdnaSite("TestStaticConfiguration") strParam2 = EDConfigurationStatic.getStringValue( "EDPluginTestPluginFactory", "testItemName") EDAssert.equal(False, strParam1 == strParam2, "Static config is not equal to local config")
def unitTestArchSize(self): """ Test architecture and size """ EDVerbose.DEBUG("EDTestCaseEDUtilsPlatform.unitTestArchSize") if EDUtilsPlatform.size == 64: EDAssert.equal(distutils.util.get_platform(), EDUtilsPlatform.getPythonPlatform(), "distutil.util.get_platform") else: EDAssert.equal(distutils.util.get_platform(), EDUtilsPlatform.getSystemPlatform(), "distutil.util.get_platform")
def testExecute(self): EDTestCasePluginExecuteControlGridScreeningv1_0.testExecute(self) edPlugin = self.getPlugin() # Check that we have the image quality indicators xsDataResult = edPlugin.getDataOutput() EDAssert.equal(False, xsDataResult.getImageQualityIndicators() is None, "Result contains image quality indicators") # Check that we don't have the indexing result EDAssert.equal(True, xsDataResult.getMosaicity() is None, "Result doesn't contain the mosaicity estimation")
def testGenerateMOSFLMCommands(self): """ """ pluginIndexing = self.createPlugin() pluginIndexing.setScriptExecutable("cat") pluginIndexing.configure() xsDataMOSFLMInputIndexing = self.generateDataMOSFLMInputIndexing() pluginIndexing.setDataInput(xsDataMOSFLMInputIndexing) pluginIndexing.generateMOSFLMCommands() listCommandsReference = ['WAVELENGTH 0.934', 'DISTANCE 198.4', 'BEAM 102.5 104.7', 'DETECTOR ADSC', 'DIRECTORY ' + self.strDataImagePath, 'TEMPLATE ref-testscale_1_###.img', 'NEWMAT ' + pluginIndexing.getNewmatFileName(), 'AUTOINDEX DPS REFINE IMAGE 1 PHI 0.0 1.0', 'AUTOINDEX DPS REFINE IMAGE 2 PHI 90.0 91.0', 'GO', 'MOSAIC ESTIMATE 1', 'GO', 'MOSAIC ESTIMATE 2', 'GO'] listCommands = pluginIndexing.getListCommandExecution() EDAssert.equal(listCommandsReference, listCommands) self.cleanUp(pluginIndexing)
def testExecute(self): """ """ self.run() plugin = self.getPlugin() # plugin.synchronize() strExpectedOutput = self.readAndParseFile (self.getReferenceDataOutputFile()) EDVerbose.DEBUG("Checking obtained result...") xsDataResultReference = self.XSDataResult.parseString(strExpectedOutput) xsDataResultObtained = plugin.getDataOutput() EDAssert.equal(xsDataResultReference.marshal(), xsDataResultObtained.marshal(), "XML are the same")
def testExecuteActionClusterWithFailure(self): """ Test the EDActionCluster with actions ending in success """ edActionCluster = EDActionCluster() for i in range(10): edAction = EDActionSuccess() edActionCluster.addAction(edAction) edActionFailure = EDActionFailure() edActionCluster.addAction(edActionFailure) edActionCluster.executeSynchronous() EDAssert.equal(True, edActionCluster.isFailure(), "EDActionCluster ended in failure")
def testExecute(self): """ Runs the plugin and then compares expected output with obtained output to verify that it executed correctly. """ self.run() # Check that the id extists in the results edPlugin = self.getPlugin() xsDataResult = edPlugin.getDataOutput() bAttributeExists = True if xsDataResult.workflowId is None: bAttributeExists = False EDAssert.equal(True, bAttributeExists, "Attribute workflowId in the result")
def testInitaliseLabelitCommandLine(self): """ This method tests the initaliseLabelitCommandLine method of the Labelit plugin. """ edPluginLabelitv1_1 = self.createPlugin() xmlInput1 = EDUtilsFile.readFile(self.__strReferenceInputFile1) edPluginLabelitv1_1.setDataInput(xmlInput1, "referenceImage") xmlInput2 = EDUtilsFile.readFile(self.__strReferenceInputFile2) edPluginLabelitv1_1.setDataInput(xmlInput2, "referenceImage") edPluginLabelitv1_1.initaliseLabelitCommandLine() strScriptCommandLine = edPluginLabelitv1_1.getScriptCommandline() strCommandLineExpected = "--index_only ${EDNA_TESTIMAGES}/images/ref-testscale_1_001.img ${EDNA_TESTIMAGES}/images/ref-testscale_1_002.img" EDAssert.equal(strCommandLineExpected, strScriptCommandLine)
def testExecute(self): """ execute the execution test """ self.run() # Checks the expected result strExpectedOutput = self.readAndParseFile (self.getReferenceDataOutputFile()) strObtainedOutput = self.readAndParseFile (self.m_edObtainedOutputDataFile) EDVerbose.DEBUG("Checking obtained result...") xsDataResultReference = XSDataResultExecCommandLine.parseString(strExpectedOutput) xsDataResultObtained = XSDataResultExecCommandLine.parseString(strObtainedOutput) EDAssert.equal(xsDataResultReference.marshal(), xsDataResultObtained.marshal())
def testExecute(self): """ """ self.run() plugin = self.getPlugin() # Checking obtained results xsDataResult = plugin.getDataOutput() ref = self.readAndParseFile(self.getReferenceDataOutputFile()) obt = xsDataResult.marshal() # EDVerbose.DEBUG("Reference: %s" % ref) # EDVerbose.DEBUG("Obtained: %s" % obt) EDAssert.equal(ref, obt, "XML object comparison")
def testGetXSDataResultBest4(self): edPluginBest = self.createPlugin() xsDataInputBest = XSDataInputBest() edPluginBest.dataInput = xsDataInputBest # Test 1 xsDataResultBest = edPluginBest.getXSDataResultBest( os.path.join(self.strDataPath, "unit_test_4_best.log")) xsDataResultBestReference = XSDataResultBest.parseFile( os.path.join(self.strDataPath, "XSDataResultBest_unit_test_4.xml")) print xsDataResultBest.marshal() EDAssert.equal(xsDataResultBestReference.collectionPlan[0].marshal(), xsDataResultBest.collectionPlan[0].marshal(), "Collection plan")
def unitTestGetSIValue(self): """ test the execution of unitTestGetSIValue static method """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetSIValue") xsd = XSDataLength(1.5) xsd.setUnit(XSDataString("mm")) EDAssert.equal(0.0015, EDUtilsUnit.getSIValue(xsd), "Conversion mm to meter") xsd = XSDataAngle(90) xsd.setUnit(XSDataString("deg")) EDAssert.equal(math.pi / 2, EDUtilsUnit.getSIValue(xsd), "Conversion deg to rad")
def testWriteDataOutput(self): # Test 1: default Output with XML edPlugin = EDPlugin() edPlugin.configure() xsDataStringTest = XSDataString("Test") edPlugin.setDataOutput(xsDataStringTest) edPlugin.writeDataOutput() EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_dataOutput.xml")), "Test 1: default Output with XML") # Test 2: named Output with XML edPlugin = EDPlugin() edPlugin.configure() xsDataStringTest = XSDataString("Test") edPlugin.setDataOutput(xsDataStringTest, "testData") edPlugin.writeDataOutput() EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_testData_0_dataOutput.xml")), "Test 2: named Output with XML") # Test 3: several Outputs with the same name, XML Output edPlugin = EDPlugin() edPlugin.configure() xsDataStringTest1 = XSDataString("Test1") xsDataStringTest2 = XSDataString("Test2") edPlugin.setDataOutput(xsDataStringTest1, "testData") edPlugin.setDataOutput(xsDataStringTest2, "testData") edPlugin.writeDataOutput() EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_testData_0_dataOutput.xml")), "Test 3: several Outputs with the same name, XML Output, 1") EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_testData_1_dataOutput.xml")), "Test 3: several Outputs with the same name, XML Output, 2")
def testExecute(self): EDTestCasePluginExecuteControlCharacterisationv1_1.testExecute(self) plugin = self.getPlugin() xsDataCharacterisation = plugin.getDataOutput() xsDataCollectionPlanList = xsDataCharacterisation.getStrategyResult( ).getCollectionPlan() EDAssert.equal(2, len(xsDataCollectionPlanList)) strRankingResolutionInitial = xsDataCollectionPlanList[ 1].getStrategySummary().getResolutionReasoning().getValue() EDAssert.equal( "Resolution limit is set by the initial image resolution", strRankingResolutionInitial) #Ric: to avoid error: strRankingResolutionLow = xsDataCollectionPlanList[ 0].getStrategySummary().getResolutionReasoning().getValue() if (plugin.getPluginStrategyName == "EDPluginControlStrategyv1_1"): EDAssert.equal("Low-resolution pass, no overloads", strRankingResolutionLow) elif (plugin.getPluginStrategyName == "EDPluginControlStrategyv1_2"): EDAssert.equal( "Low-resolution pass, no overloads and full completeness", strRankingResolutionLow)
def testGetEdnaUserTempFolder(self): # Test that we can access the user temp folder strUserTempFolder = EDUtilsPath.getEdnaUserTempFolder() EDAssert.equal(True, os.path.exists(strUserTempFolder), "Checking that user temp folder exists") # Test if we can write to the temp folder strTest = "This is a test string." strPathTestFile = os.path.join(strUserTempFolder, "EDTestCaseEDUtilsPath_testFile.txt") EDUtilsFile.writeFile(strPathTestFile, strTest) EDAssert.equal(True, os.path.exists(strPathTestFile), "Checking that new temp file exists") # Delete the test file os.remove(strPathTestFile)
def testInitaliseLabelitCommandLine(self): """ This method tests the initaliseLabelitCommandLine method of the Labelit plugin. """ edPluginLabelitv10 = self.createPlugin() strReferenceInputFile = os.path.join( self.getPluginTestsDataHome(), "XSDataInputLabelit_testCommandLine.xml") xmlInput = self.readAndParseFile(strReferenceInputFile) edPluginLabelitv10.setDataInput(xmlInput) edPluginLabelitv10.initaliseLabelitCommandLine() strScriptCommandLine = edPluginLabelitv10.getScriptCommandline() strCommandLineExpected = "--index_only images/ref-testscale_1_001.img images/ref-testscale_1_002.img" EDAssert.equal(strCommandLineExpected, strScriptCommandLine)
def testExecute( self ): """ """ self.run() # Checks that there are no error messages plugin = self.getPlugin() EDVerbose.DEBUG("Checking error messages...") EDAssert.equal( self.m_iNoErrorMessages, self.getErrorMessages().getNumberObjects() ) EDVerbose.DEBUG("Checking warning messages...") EDAssert.equal( self.m_iNoWarningMessages, self.getWarningMessages().getNumberObjects() )
def testExecute(self): self.run() # Checks that there are no error messages plugin = self.getPlugin() # Checks the expected result EDVerbose.DEBUG("Checking obtained result...") xsDataResultControlISPyB = plugin.dataOutput bExistScreeningId = False if xsDataResultControlISPyB.screeningId is not None: bExistScreeningId = True EDAssert.equal(True, bExistScreeningId, "Screening id generated")
def testExecute(self): EDTestCasePluginExecuteControlCharacterisationv1_3.testExecute(self) edPlugin = self.getPlugin() strStatusMessage = None if edPlugin.hasDataOutput("statusMessage"): strStatusMessage = edPlugin.getDataOutput( "statusMessage")[0].getValue() EDAssert.equal(True, strStatusMessage.find("Indexing FAILURE") != -1, "Status message contains 'Indexing FAILURE'") edPlugin.generateExecutiveSummary(edPlugin) edPlugin.verboseScreenExecutiveSummary()
def testWriteDataInput(self): # Test 1: default input with XML edPlugin = EDPlugin() edPlugin.configure() edPlugin.setXSDataInputClass(XSDataString) xsDataStringTest = XSDataString("Test") edPlugin.setDataInput(xsDataStringTest.marshal()) edPlugin.writeDataInput() EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_dataInput.xml")), "Test 1: default input with XML") # Test 2: named input with XML edPlugin = EDPlugin() edPlugin.configure() edPlugin.setXSDataInputClass(XSDataString, "testData") xsDataStringTest = XSDataString("Test") edPlugin.setDataInput(xsDataStringTest.marshal(), "testData") edPlugin.writeDataInput() EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_testData_0_dataInput.xml")), "Test 2: named input with XML") # Test 3: several inputs with the same name, XML input edPlugin = EDPlugin() edPlugin.configure() edPlugin.setXSDataInputClass(XSDataString, "testData") xsDataStringTest1 = XSDataString("Test1") xsDataStringTest2 = XSDataString("Test2") edPlugin.setDataInput(xsDataStringTest1.marshal(), "testData") edPlugin.setDataInput(xsDataStringTest2.marshal(), "testData") edPlugin.writeDataInput() EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_testData_0_dataInput.xml")), "Test 3: several inputs with the same name, XML input, 1") EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_testData_1_dataInput.xml")), "Test 3: several inputs with the same name, XML input, 2")
def testParseParameterFile(self): edPluginControlID11 = self.createPlugin() # Path to test parameter file strDataPath = self.getPluginTestsDataHome() strTestParameterFile = "id11_parameterFile_reference.txt" strPath = os.path.join(strDataPath, strTestParameterFile) dictID11 = edPluginControlID11.parseParameterFiles(strPath) # dictSub = os.environ.copy() # dictSub["TEST_DATA_IMAGES_HOME"] = EDUtilsTest.getTestsDataImagesHome() # for keyId11 in dictID11: # for key in dictSub: # dictID11[keyId11] = dictID11[keyId11].replace("${%s}" % key , dictSub[ key ]) EDAssert.equal(self.dictID11Reference, dictID11, "Dictionaries are the same")
def testGetProjectRootDirectory(self): edFactoryPluginTest = EDFactoryPluginTest() strEdnaHome = EDUtilsPath.getEdnaHome() strTestProjectRootDirectoryReference = EDUtilsPath.appendListOfPaths( strEdnaHome, ["kernel", "tests", "data", "EDFactoryPlugin", "testProject"]) strTestProjectRootDirectory1 = edFactoryPluginTest.getProjectRootDirectory( "EDTestCasePluginUnitTestPluginFactory") EDAssert.equal(strTestProjectRootDirectoryReference, strTestProjectRootDirectory1) strTestProjectRootDirectory2 = edFactoryPluginTest.getProjectRootDirectory( "EDTestSuitePluginUnitTestProject") EDAssert.equal(strTestProjectRootDirectoryReference, strTestProjectRootDirectory2)
def testExecute(self): # Start a timer for copying the file pyTimer = Timer(5, self.copyFile) pyTimer.start() self.run() pyTimer.cancel() # Check timeout edPlugin = self.getPlugin() EDAssert.equal(False, edPlugin.dataOutput.timedOut.value, "TimedOut should be False") time.sleep(1) shutil.rmtree(self.strTmpDir) if self.strTmpDirOrig is not None: os.environ["EDNA_TMP_DIR"] = self.strTmpDirOrig