Module EDTestCaseEDConfiguration
[hide private]
[frames] | no frames]

Source Code for Module EDTestCaseEDConfiguration

  1  # 
  2  #    Project: The EDNA Kernel 
  3  #             http://www.edna-site.org 
  4  # 
  5  #    Copyright (C) 2008-2012 European Synchrotron Radiation Facility 
  6  #                            Grenoble, France 
  7  # 
  8  #    Principal authors: Marie-Francoise Incardona (incardon@esrf.fr) 
  9  #                       Olof Svensson (svensson@esrf.fr)  
 10  # 
 11  #    This program is free software: you can redistribute it and/or modify 
 12  #    it under the terms of the GNU Lesser General Public License as published 
 13  #    by the Free Software Foundation, either version 3 of the License, or 
 14  #    (at your option) any later version. 
 15  # 
 16  #    This program is distributed in the hope that it will be useful, 
 17  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 18  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 19  #    GNU Lesser General Public License for more details. 
 20  # 
 21  #    You should have received a copy of the GNU General Public License 
 22  #    and the GNU Lesser General Public License  along with this program.   
 23  #    If not, see <http://www.gnu.org/licenses/>. 
 24  # 
 25   
 26  __authors__ = [ "Marie-Francoise Incardona", "Olof Svensson" ] 
 27  __contact__ = "svensson@esrf.fr" 
 28  __license__ = "LGPLv3+" 
 29  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
 30   
 31   
 32  """ 
 33  This is the test case for the EDConfiguration class. 
 34  """ 
 35   
 36  import os 
 37   
 38  from EDAssert                import EDAssert 
 39  from EDConfiguration         import EDConfiguration 
 40  from EDConfigurationStatic   import EDConfigurationStatic 
 41  from EDUtilsTest             import EDUtilsTest 
 42  from EDUtilsPath             import EDUtilsPath 
 43  from EDTestCase              import EDTestCase 
 44   
 45  from XSDataCommon import XSPluginItem 
 46   
47 -class EDTestCaseEDConfiguration(EDTestCase):
48 49
50 - def __init__(self, _strTestName=None):
51 EDTestCase.__init__(self, "EDTestCaseEDConfiguration") 52 strKernelDataHome = EDUtilsTest.getPluginTestDataDirectory(self.getClassName()) 53 strDataDir = "EDConfiguration" 54 self.strDataPath = EDUtilsPath.mergePath(strKernelDataHome, strDataDir) 55 self.strEdnaSiteOrig = EDUtilsPath.getEdnaSite()
56 57
58 - def preProcess(self):
59 """Set EDNA_SITE to TestSite for these tests""" 60 EDUtilsPath.setEdnaSite("TestSite")
61 62
63 - def testAddConfigFile(self):
64 # Tests adding a config file 65 strPath = os.path.join(self.strDataPath, "XSConfiguration.xml") 66 edConfiguration = EDConfiguration() 67 edConfiguration.addConfigurationFile(strPath) 68 # Load the config file again, this time the cache should be used 69 edConfiguration.addConfigurationFile(strPath)
70 71
73 strPath = os.path.join(self.strDataPath, "XSConfiguration.xml") 74 edConfiguration = EDConfiguration() 75 edConfiguration.addConfigurationFile(strPath) 76 xsDataPluginItem = edConfiguration.getXSConfigurationItem("indexingMosflm") 77 EDAssert.equal(True, xsDataPluginItem is not None, "Obtanied configuration for indexingMosflm")
78
80 edConfiguration = EDConfiguration() 81 xsDataPluginItem1 = edConfiguration.getXSConfigurationItem("EDPluginTestPluginFactory") 82 EDAssert.equal(True, xsDataPluginItem1 is not None, "Obtanied configuration for EDPluginTestPluginFactory") 83 xsDataPluginItem2 = edConfiguration.getXSConfigurationItem("EDPluginTestPluginFactoryImport1") 84 EDAssert.equal(True, xsDataPluginItem2 is not None, "Obtanied imported configuration for EDPluginTestPluginFactoryImport1") 85 xsDataPluginItem3 = edConfiguration.getXSConfigurationItem("EDPluginTestPluginFactoryImport2") 86 EDAssert.equal(True, xsDataPluginItem3 is not None, "Obtanied imported configuration for EDPluginTestPluginFactoryImport2")
87 88
90 xsPluginItem = XSPluginItem() 91 xsPluginItem.name = "EDPluginTestSetConfig" 92 edConfiguration = EDConfiguration() 93 edConfiguration.setXSConfigurationItem(xsPluginItem) 94 xsDataPluginItem = edConfiguration.getXSConfigurationItem("EDPluginTestSetConfig") 95 EDAssert.equal(True, xsDataPluginItem is not None, "Obtanied set configuration")
96 97
99 edConfiguration = EDConfiguration() 100 strPathToConfigurationFile1 = edConfiguration.getPathToProjectConfigurationFile("EDPluginTestPluginFactory") 101 strPathToConfigurationFileReference1 = EDUtilsPath.appendListOfPaths(EDUtilsPath.getEdnaHome(), 102 [ "kernel", "tests", "data", "EDFactoryPlugin", \ 103 "testProject", "conf", "XSConfiguration_TestSite.xml" ]) 104 EDAssert.equal(strPathToConfigurationFileReference1, strPathToConfigurationFile1) 105 EDUtilsPath.setEdnaSite("NonexistingTestSite") 106 strPathToConfigurationFile2 = edConfiguration.getPathToProjectConfigurationFile("EDPluginTestPluginFactory") 107 strPathToConfigurationFileReference2 = None 108 EDAssert.equal(strPathToConfigurationFileReference2, strPathToConfigurationFile2)
109 110
112 # This test make sure that changing an instatiation of EDConfiguration does not change the 113 # corresponding plugin configuration for EDConfigurationStatic 114 strPathToTestConfigFile = os.path.join(self.strDataPath, "XSConfiguration_testNonStatic.xml") 115 edConfiguration = EDConfiguration(strPathToTestConfigFile) 116 strParam1 = edConfiguration.getStringValue("EDPluginTestPluginFactory", "testItemName") 117 EDUtilsPath.setEdnaSite("TestStaticConfiguration") 118 strParam2 = EDConfigurationStatic.getStringValue("EDPluginTestPluginFactory", "testItemName") 119 EDAssert.equal(False, strParam1 == strParam2, "Static config is not equal to local config")
120 121
122 - def finallyProcess(self):
123 """Restores EDNA_SITE""" 124 EDUtilsPath.setEdnaSite(self.strEdnaSiteOrig)
125 126 127
128 - def testGetPluginListSize(self):
129 """ 130 Testing the retrieved XSPluginList size from configuration 131 """ 132 strPath = os.path.join(self.strDataPath, "XSConfiguration.xml") 133 edConfiguration = EDConfiguration() 134 edConfiguration.addConfigurationFile(strPath) 135 iPluginListSize = edConfiguration.getPluginListSize() 136 EDAssert.equal(1, iPluginListSize)
137 138
139 - def testGetPluginItem(self):
140 """ 141 Testing Plugin indexingMosflm Configuration 142 """ 143 strPath = os.path.join(self.strDataPath, "XSConfiguration.xml") 144 edConfiguration = EDConfiguration() 145 edConfiguration.addConfigurationFile(strPath) 146 xsPluginItem = edConfiguration.getXSConfigurationItem("indexingMosflm") 147 EDAssert.equal("indexingMosflm", xsPluginItem.getName()) 148 149 paramList = xsPluginItem.getXSParamList() 150 paramItems = paramList.getXSParamItem() 151 152 EDAssert.equal("workingDir", paramItems[0].getName()) 153 EDAssert.equal("/path/to/working/dir", paramItems[0].getValue()) 154 EDAssert.equal("number", paramItems[1].getName()) 155 EDAssert.equal("3", paramItems[1].getValue())
156 157
158 - def testGetPluginItemError(self):
159 """ 160 Testing the retrieval of an absent plugin 161 """ 162 strPath = os.path.join(self.strDataPath, "XSConfiguration.xml") 163 edConfiguration = EDConfiguration() 164 edConfiguration.addConfigurationFile(strPath) 165 xsPluginItem = edConfiguration.getXSConfigurationItem("toto") 166 EDAssert.equal(None, xsPluginItem, "Non-existing configuration item should be None")
167 168
169 - def testGetParamItem(self):
170 """ 171 Testing the XSParamItem inside an XSPluginItem 172 """ 173 strPath = os.path.join(self.strDataPath, "XSConfiguration.xml") 174 edConfiguration = EDConfiguration() 175 edConfiguration.addConfigurationFile(strPath) 176 strValue = edConfiguration.getStringValue("indexingMosflm", "workingDir") 177 EDAssert.equal("/path/to/working/dir", strValue)
178 179
180 - def testGetParamValue(self):
181 """ 182 Testing the XSParamItem Value convertion from string to different formats 183 """ 184 strPath = os.path.join(self.strDataPath, "XSConfiguration.xml") 185 edConfiguration = EDConfiguration() 186 edConfiguration.addConfigurationFile(strPath) 187 xsPluginItem = edConfiguration.getXSConfigurationItem("indexingMosflm") 188 EDAssert.equal("/path/to/working/dir", edConfiguration.getStringParamValue(xsPluginItem, "workingDir")) 189 EDAssert.equal("/path/to/working/dir", EDConfiguration.getStringParamValue(xsPluginItem, "workingDir")) 190 EDAssert.equal(3, edConfiguration.getIntegerParamValue(xsPluginItem, "number")) 191 EDAssert.equal(3, EDConfiguration.getIntegerParamValue(xsPluginItem, "number"))
192 193
194 - def process(self):
206 207 208 if __name__ == '__main__': 209 210 edTestCaseEDConfiguration = EDTestCaseEDConfiguration("EDTestCaseEDConfiguration") 211 edTestCaseEDConfiguration.execute() 212