Mercurial > repos > yufei-luo > s_mart
comparison smart_toolShed/commons/core/checker/test/Test_OldConfigChecker.py @ 0:e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
author | yufei-luo |
---|---|
date | Thu, 17 Jan 2013 10:52:14 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e0f8dcca02ed |
---|---|
1 # Copyright INRA (Institut National de la Recherche Agronomique) | |
2 # http://www.inra.fr | |
3 # http://urgi.versailles.inra.fr | |
4 # | |
5 # This software is governed by the CeCILL license under French law and | |
6 # abiding by the rules of distribution of free software. You can use, | |
7 # modify and/ or redistribute the software under the terms of the CeCILL | |
8 # license as circulated by CEA, CNRS and INRIA at the following URL | |
9 # "http://www.cecill.info". | |
10 # | |
11 # As a counterpart to the access to the source code and rights to copy, | |
12 # modify and redistribute granted by the license, users are provided only | |
13 # with a limited warranty and the software's author, the holder of the | |
14 # economic rights, and the successive licensors have only limited | |
15 # liability. | |
16 # | |
17 # In this respect, the user's attention is drawn to the risks associated | |
18 # with loading, using, modifying and/or developing or reproducing the | |
19 # software by the user in light of its specific status of free software, | |
20 # that may mean that it is complicated to manipulate, and that also | |
21 # therefore means that it is reserved for developers and experienced | |
22 # professionals having in-depth computer knowledge. Users are therefore | |
23 # encouraged to load and test the software's suitability as regards their | |
24 # requirements in conditions enabling the security of their systems and/or | |
25 # data to be ensured and, more generally, to use and operate it in the | |
26 # same conditions as regards security. | |
27 # | |
28 # The fact that you are presently reading this means that you have had | |
29 # knowledge of the CeCILL license and that you accept its terms. | |
30 | |
31 | |
32 import unittest | |
33 import os | |
34 from commons.core.checker.OldConfigChecker import ConfigChecker | |
35 from commons.core.checker.ConfigException import ConfigException | |
36 | |
37 class Test_ConfigChecker( unittest.TestCase ): | |
38 | |
39 def setUp(self): | |
40 pass | |
41 | |
42 def tearDown(self): | |
43 pass | |
44 | |
45 | |
46 def testFileNotFound(self): | |
47 exceptionExpected = None | |
48 configChecker = ConfigChecker("",{}) | |
49 try : | |
50 configChecker.check("noExistsFile.cfg") | |
51 except ConfigException, ce: | |
52 exceptionExpected = ce | |
53 | |
54 self.assertTrue(exceptionExpected != None) | |
55 msg = exceptionExpected.messages[0] | |
56 self.assertTrue(msg.startswith("CONFIG FILE not found - ")) | |
57 | |
58 | |
59 def testNoSectionInConfigFile (self): | |
60 exceptionExpected = None | |
61 dummyFile = open("dummyFile.cfg", "w") | |
62 configChecker = ConfigChecker("dummySection",{}) | |
63 try : | |
64 configChecker.check("dummyFile.cfg") | |
65 except ConfigException, ce: | |
66 exceptionExpected = ce | |
67 | |
68 self.assertTrue(exceptionExpected != None) | |
69 msg = exceptionExpected.messages[0] | |
70 self.assertTrue(msg.startswith("[dummySection]" + " section not found - ")) | |
71 | |
72 os.remove("dummyFile.cfg") | |
73 | |
74 | |
75 def testNoOptionInConfigFile (self): | |
76 exceptionExpected = None | |
77 MockConfigFile("dummyConfig.cfg",{}) | |
78 configChecker = ConfigChecker("blaster_config",{"dummy":""}) | |
79 try : | |
80 configChecker.check("dummyConfig.cfg") | |
81 except ConfigException, ce: | |
82 exceptionExpected = ce | |
83 | |
84 self.assertTrue(exceptionExpected != None) | |
85 msg = exceptionExpected.messages[0] | |
86 self.assertTrue(msg.startswith("[blaster_config] - No option 'dummy' in section: 'blaster_config'")) | |
87 os.remove("dummyConfig.cfg") | |
88 | |
89 | |
90 class MockConfigFile: | |
91 | |
92 def __init__ (self, fileName, optionsDict): | |
93 self._fileName = fileName | |
94 config = open(fileName, "w"); | |
95 config.write("[blaster_config]\n") | |
96 for key in optionsDict.keys(): | |
97 config.write(key + ":" + optionsDict[key] + "\n") | |
98 config.close() | |
99 | |
100 | |
101 test_suite = unittest.TestSuite() | |
102 test_suite.addTest( unittest.makeSuite( Test_ConfigChecker ) ) | |
103 if __name__ == "__main__": | |
104 unittest.TextTestRunner(verbosity=2).run( test_suite ) |