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

Source Code for Module EDTestCaseEDUtilsFile

 1  # coding: utf8 
 2  # 
 3  #    Project: The EDNA Kernel 
 4  #             http://www.edna-site.org 
 5  # 
 6  #    File: "$Id$" 
 7  # 
 8  #    Copyright (C) 2008-2009 European Synchrotron Radiation Facility 
 9  #                            Grenoble, France 
10  # 
11  #    Principal authors: Olof Svensson (svensson@esrf.fr) 
12  # 
13  #    Contribution from: Jérôme Kieffer (jerome.kieffer@esrf.eu) 
14  # 
15  #    This program is free software: you can redistribute it and/or modify 
16  #    it under the terms of the GNU Lesser General Public License as published 
17  #    by the Free Software Foundation, either version 3 of the License, or 
18  #    (at your option) any later version. 
19  # 
20  #    This program is distributed in the hope that it will be useful, 
21  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
22  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
23  #    GNU Lesser General Public License for more details. 
24  # 
25  #    You should have received a copy of the GNU General Public License 
26  #    and the GNU Lesser General Public License  along with this program.   
27  #    If not, see <http://www.gnu.org/licenses/>. 
28  # 
29   
30  __authors__ = [ "Olof Svensson", "Jérôme Kieffer" ] 
31  __contact__ = "svensson@esrf.fr" 
32  __license__ = "LGPLv3+" 
33  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
34   
35  """ 
36  This is the test case for the EDUtilsFile static class. 
37  """ 
38   
39   
40  import os, tempfile 
41   
42  from EDTestCase     import EDTestCase 
43  from EDVerbose      import EDVerbose 
44  from EDAssert       import EDAssert 
45  from EDUtilsFile    import EDUtilsFile 
46   
47 -class EDTestCaseEDUtilsFile(EDTestCase):
48 49
50 - def __init__(self, _strTestName=None):
51 EDTestCase.__init__(self, "EDTestCaseEDUtilsFile")
52 53
55 # Test 1 - just with environment variables in a file 56 os.environ["TEST_XSCONFIGURATION1"] = "TEST1" 57 os.environ["TEST_XSCONFIGURATION2"] = "TEST2" 58 strTest1 = "This is a test: ${TEST_XSCONFIGURATION1}, another test ${TEST_XSCONFIGURATION2}" 59 (fd, strFileName1) = tempfile.mkstemp(prefix="EDTestCaseEDUtilsFile-", suffix=".xml", text=True) 60 os.close(fd) 61 EDUtilsFile.writeFile(strFileName1, strTest1) 62 strReference1 = "This is a test: TEST1, another test TEST2" 63 strResult1 = EDUtilsFile.readFileAndParseVariables(strFileName1) 64 EDAssert.equal(strReference1, strResult1, "Just with environment variables in a file") 65 EDUtilsFile.deleteFile(strFileName1) 66 # Test 2 - with a file and a dictionary 67 strTest2 = "This is a second test: ${TEST_XSCONFIGURATION1}, ${EDNA_VARIABLE}, another test ${TEST_XSCONFIGURATION2} and another ${EDNA_VARIABLE2}." 68 dictTest = { "${EDNA_VARIABLE}" : "EDNA1", "${EDNA_VARIABLE2}" : "EDNA2"} 69 (fd, strFileName2) = tempfile.mkstemp(prefix="EDTestCaseEDUtilsFile-", suffix=".xml", text=True) 70 os.close(fd) 71 EDUtilsFile.writeFile(strFileName2, strTest2) 72 strReference2 = "This is a second test: TEST1, EDNA1, another test TEST2 and another EDNA2." 73 strResult2 = EDUtilsFile.readFileAndParseVariables(strFileName2, dictTest) 74 EDAssert.equal(strReference2, strResult2, "with a file and a dictionary") 75 EDUtilsFile.deleteFile(strFileName2)
76 77
78 - def process(self):
80 81 82 if __name__ == '__main__': 83 84 edTestCaseEDUtilsFile = EDTestCaseEDUtilsFile("EDTestCaseEDUtilsFile") 85 edTestCaseEDUtilsFile.execute() 86