def testCopyHTMLFilesAndDir(self): if not os.path.exists(EDUtilsPath.getEdnaUserTempFolder()): os.mkdir(EDUtilsPath.getEdnaUserTempFolder()) strTestFromDir = os.path.join(EDUtilsPath.getEdnaUserTempFolder(), "TestFromDir") shutil.rmtree(strTestFromDir, ignore_errors=True) os.mkdir(strTestFromDir) strTestHtmlFilePath = os.path.join(strTestFromDir, "index.html") strTestHtmlDirPath = os.path.join(strTestFromDir, "index") EDUtilsFile.writeFile(strTestHtmlFilePath, "Test content") if not os.path.exists(strTestHtmlDirPath): os.mkdir(strTestHtmlDirPath) strTestHtmlDirFilePath = os.path.join(strTestHtmlDirPath, "test.txt") EDUtilsFile.writeFile(strTestHtmlDirFilePath, "Test content") # strTestToDir = os.path.join(EDUtilsPath.getEdnaUserTempFolder(), "TestToDir") shutil.rmtree(strTestToDir, ignore_errors=True) os.mkdir(strTestToDir) EDHandlerESRFPyarchv1_0.copyHTMLDir(strTestFromDir, strTestToDir) # # Check that files exist in strTestToDir: EDAssert.isFile(os.path.join(strTestToDir, "index", "index.html")) EDAssert.isFile(os.path.join(strTestToDir, "index", "index", "test.txt")) # shutil.rmtree(strTestFromDir, ignore_errors=True) shutil.rmtree(strTestToDir, ignore_errors=True)
def testCopyHTMLFilesAndDir(self): if not os.path.exists(EDUtilsPath.getEdnaUserTempFolder()): os.mkdir(EDUtilsPath.getEdnaUserTempFolder()) strTestFromDir = os.path.join(EDUtilsPath.getEdnaUserTempFolder(), "TestFromDir") shutil.rmtree(strTestFromDir, ignore_errors=True) os.mkdir(strTestFromDir) strTestHtmlFilePath = os.path.join(strTestFromDir, "index.html") strTestHtmlDirPath = os.path.join(strTestFromDir, "index") EDUtilsFile.writeFile(strTestHtmlFilePath, "Test content") if not os.path.exists(strTestHtmlDirPath): os.mkdir(strTestHtmlDirPath) strTestHtmlDirFilePath = os.path.join(strTestHtmlDirPath, "test.txt") EDUtilsFile.writeFile(strTestHtmlDirFilePath, "Test content") # strTestToDir = os.path.join(EDUtilsPath.getEdnaUserTempFolder(), "TestToDir") shutil.rmtree(strTestToDir, ignore_errors=True) os.mkdir(strTestToDir) EDHandlerESRFPyarchv1_0.copyHTMLDir(strTestFromDir, strTestToDir) # # Check that files exist in strTestToDir: EDAssert.isFile(os.path.join(strTestToDir, "index", "index.html")) EDAssert.isFile( os.path.join(strTestToDir, "index", "index", "test.txt")) # shutil.rmtree(strTestFromDir, ignore_errors=True) shutil.rmtree(strTestToDir, ignore_errors=True)
def finallyProcess(self, _edPlugin=None): EDPluginExec.finallyProcess(self, _edPlugin) self.DEBUG("EDPluginExecSimpleHTMLPagev1_1.finallyProcess...") xsDataResultSimpleHTMLPage = XSDataResultSimpleHTMLPage() xsDataResultSimpleHTMLPage.setPathToHTMLFile(XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), self.strHtmlFileName)))) xsDataResultSimpleHTMLPage.setPathToHTMLDirectory(XSDataFile(XSDataString(self.getWorkingDirectory()))) # Write workflowStepReport HTML page pathToIndexFile = self.workflowStepReport.renderHtml(self.getWorkingDirectory(), nameOfIndexFile=self.strHtmlFileName) pathToJsonFile = self.workflowStepReport.renderJson(self.getWorkingDirectory()) # Store in Pyarch if EDUtilsPath.isESRF() or EDUtilsPath.isEMBL() or EDUtilsPath.isMAXIV() or EDUtilsPath.isALBA: strPyarchPath = None if self.xsDataResultCharacterisation is not None: strPyarchPath = EDHandlerESRFPyarchv1_0.createPyarchHtmlDirectoryPath(self.xsDataResultCharacterisation.getDataCollection()) if strPyarchPath is None: # For debugging purposes strPyarchPath = EDUtilsPath.getEdnaUserTempFolder() EDHandlerESRFPyarchv1_0.copyHTMLDir(_strPathToHTMLDir=os.path.dirname(self.strPath), _strPathToPyarchDirectory=strPyarchPath) xsDataResultSimpleHTMLPage.setPathToHTMLDirectory(XSDataFile(XSDataString(strPyarchPath))) if not os.path.exists(strPyarchPath): os.makedirs(strPyarchPath, 0o755) shutil.copy(pathToJsonFile, strPyarchPath) pathToJsonFile = os.path.join(strPyarchPath, os.path.basename(pathToJsonFile)) # Write json file xsDataResultSimpleHTMLPage.pathToJsonFile = XSDataFile(XSDataString(pathToJsonFile)) self.setDataOutput(xsDataResultSimpleHTMLPage)
def finallyProcess(self, _edPlugin=None): EDPluginExec.finallyProcess(self, _edPlugin) self.DEBUG("EDPluginExecSimpleHTMLPagev1_1.finallyProcess...") xsDataResultSimpleHTMLPage = XSDataResultSimpleHTMLPage() xsDataResultSimpleHTMLPage.setPathToHTMLFile(XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), self.strHtmlFileName)))) xsDataResultSimpleHTMLPage.setPathToHTMLDirectory(XSDataFile(XSDataString(self.getWorkingDirectory()))) # Write workflowStepReport HTML page pathToIndexFile = self.workflowStepReport.renderHtml(self.getWorkingDirectory(), nameOfIndexFile=self.strHtmlFileName) pathToJsonFile = self.workflowStepReport.renderJson(self.getWorkingDirectory()) # Store in Pyarch if EDUtilsPath.isESRF() or EDUtilsPath.isEMBL(): strPyarchPath = None if self.xsDataResultCharacterisation is not None: strPyarchPath = EDHandlerESRFPyarchv1_0.createPyarchHtmlDirectoryPath(self.xsDataResultCharacterisation.getDataCollection()) if strPyarchPath is None: # For debugging purposes strPyarchPath = EDUtilsPath.getEdnaUserTempFolder() EDHandlerESRFPyarchv1_0.copyHTMLDir(_strPathToHTMLDir=os.path.dirname(self.strPath), _strPathToPyarchDirectory=strPyarchPath) xsDataResultSimpleHTMLPage.setPathToHTMLDirectory(XSDataFile(XSDataString(strPyarchPath))) if not os.path.exists(strPyarchPath): os.makedirs(strPyarchPath, 0o755) shutil.copy(pathToJsonFile, strPyarchPath) pathToJsonFile = os.path.join(strPyarchPath, os.path.basename(pathToJsonFile)) # Write json file xsDataResultSimpleHTMLPage.pathToJsonFile = XSDataFile(XSDataString(pathToJsonFile)) self.setDataOutput(xsDataResultSimpleHTMLPage)
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 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 finallyProcess(self, _edPlugin=None): EDPluginExec.finallyProcess(self, _edPlugin) self.DEBUG("EDPluginExecSimpleHTMLPagev1_0.finallyProcess...") # Render the page strHTML = str(self.page) EDUtilsFile.writeFile(self.strPath, strHTML) xsDataResultSimpleHTMLPage = XSDataResultSimpleHTMLPage() xsDataResultSimpleHTMLPage.setPathToHTMLFile(XSDataFile(XSDataString(self.strPath))) xsDataResultSimpleHTMLPage.setPathToHTMLDirectory(XSDataFile(XSDataString(os.path.dirname(self.strPath)))) self.setDataOutput(xsDataResultSimpleHTMLPage) # Store in Pyarch strPyarchPath = None if self.xsDataResultCharacterisation is not None: strPyarchPath = EDHandlerESRFPyarchv1_0.createPyarchHtmlDirectoryPath(self.xsDataResultCharacterisation.getDataCollection()) if strPyarchPath is None: # For debugging purposes strPyarchPath = EDUtilsPath.getEdnaUserTempFolder() EDHandlerESRFPyarchv1_0.copyHTMLDir(_strPathToHTMLDir=os.path.dirname(self.strPath), _strPathToPyarchDirectory=strPyarchPath)
def finallyProcess(self, _edPlugin=None): EDPluginExec.finallyProcess(self, _edPlugin) self.DEBUG("EDPluginExecSimpleHTMLPagev2_0.finallyProcess...") # Render the page strHTML = str(self.page) EDUtilsFile.writeFile(self.strPath, strHTML) xsDataResultSimpleHTMLPage = XSDataResultSimpleHTMLPage() xsDataResultSimpleHTMLPage.setPathToHTMLFile(XSDataFile(XSDataString(self.strPath))) xsDataResultSimpleHTMLPage.setPathToHTMLDirectory(XSDataFile(XSDataString(os.path.dirname(self.strPath)))) self.setDataOutput(xsDataResultSimpleHTMLPage) # Store in Pyarch strPyarchPath = None if self.xsDataResultCharacterisation is not None: strPyarchPath = EDHandlerESRFPyarchv1_0.createPyarchHtmlDirectoryPath(self.xsDataResultCharacterisation.getDataCollection()) if strPyarchPath is None: # For debugging purposes strPyarchPath = EDUtilsPath.getEdnaUserTempFolder() EDHandlerESRFPyarchv1_0.copyHTMLDir(_strPathToHTMLDir=os.path.dirname(self.strPath), _strPathToPyarchDirectory=strPyarchPath)
def unitTestInitialState(self): """ Check the initialization of the share: """ EDAssert.equal(False, EDShare.isInitialized(), "Check that EDShare is uninitialized") strEdnaUserTempFolder = EDUtilsPath.getEdnaUserTempFolder() EDShare.initialize(strEdnaUserTempFolder) EDShare["test1"] = range(10) EDVerbose.screen("Backend used is %s" % EDShare.backend) EDAssert.equal(1, len(EDShare.items())) EDAssert.equal(True, "test1" in EDShare, "list is actually present") for i, j in zip(range(10), EDShare["test1"]): EDAssert.equal(i, j, "elements are the same") EDShare.close() EDShare.initialize(strEdnaUserTempFolder) EDAssert.equal(True, "test1" in EDShare, "list is still present") for i, j in zip(range(10), EDShare["test1"]): EDAssert.equal(i, j, "elements are still the same") filename = EDShare.filename EDShare.close(remove=True) EDAssert.equal(False, os.path.isfile(filename), "dump-file has been removed")
def unitTestInitialState(self): """ Check the initialization of the share: """ EDAssert.equal(False, EDShare.isInitialized(), "Check that EDShare is uninitialized") strEdnaUserTempFolder = EDUtilsPath.getEdnaUserTempFolder() EDShare.initialize(strEdnaUserTempFolder) EDShare["test1"] = range(10) EDVerbose.screen("Backend used is %s" % EDShare.backend) EDAssert.equal(1, len(EDShare.items())) EDAssert.equal(True, "test1" in EDShare, "list is actually present") for i, j in zip(range(10), EDShare["test1"]): EDAssert.equal(i, j, "elements are the same") EDShare.close() EDShare.initialize(strEdnaUserTempFolder) EDAssert.equal(True, "test1" in EDShare, "list is still present") for i, j in zip(range(10), EDShare["test1"]): EDAssert.equal(i, j, "elements are still the same") filename = EDShare.filename EDShare.close(remove=True) EDAssert.equal(False, os.path.isfile(filename), "dump-file has been removed")