comparison commons/pyRepetUnit/hmmer/check/test/Test_OldDetectFeaturesConfigChecker.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 94ab73e8a190
children
comparison
equal deleted inserted replaced
30:5677346472b5 31:0ab839023fe4
1 import unittest
2 import re
3 import os
4 from commons.pyRepetUnit.hmmer.check.OldDetectFeatureConfigChecker import DetectFeatureConfigChecker
5 from commons.core.checker.ConfigException import ConfigException
6
7 class Test_DetectFeaturesConfigChecker(unittest.TestCase):
8
9 def setUp(self):
10 self._detectFeatureConfigChecker = DetectFeatureConfigChecker()
11
12 def testWithDefaultLogger (self):
13 lineFound = False
14 try:
15 self._detectFeatureConfigChecker.check("dummyConfig")
16 except ConfigException, e:
17 for msg in e.messages:
18 if (re.match("CONFIG FILE not found.*", msg)):
19 lineFound = True
20 self.assertTrue(lineFound)
21
22 def testWithNoConfigFile(self):
23 lineFound = False
24 try:
25 self._detectFeatureConfigChecker.check("dummyConfig")
26 except ConfigException, e:
27 for msg in e.messages:
28 if (re.match("CONFIG FILE not found.*", msg)):
29 lineFound = True
30 self.assertTrue(lineFound)
31
32 def testWithNoSectionInConfigFile(self):
33 config = open("config.cfg", "w");
34 config.close()
35 lineFound = False
36 try:
37 self._detectFeatureConfigChecker.check("config.cfg")
38 except ConfigException, e:
39 for msg in e.messages:
40 if (re.match("\[detect_features\] section not found.*", msg)):
41 lineFound = True
42 self.assertTrue(lineFound)
43 os.remove("config.cfg")
44
45 def testMissingOptionsInConfig (self):
46 dict = {}
47 MockConfigFile("config.cfg", dict)
48 hmmProfilsFound = False
49 TE_BLRnFound = False
50 try :
51 self._detectFeatureConfigChecker.check("config.cfg")
52 except ConfigException, e:
53 for msg in e.messages:
54 if (re.match("\[detect_features\] - No option 'te_hmmer' in section: 'detect_features'", msg)):
55 hmmProfilsFound = True
56 if (re.match("\[detect_features\] - No option 'te_blrn' in section: 'detect_features'", msg)):
57 TE_BLRnFound = True
58 self.assertTrue(hmmProfilsFound)
59 self.assertTrue(TE_BLRnFound)
60 os.remove("config.cfg")
61
62 def testOptionsIfHmmProfilsSetAtYESInConfig (self):
63
64 dict = {
65 "TE_HMMER" : "yes",
66 "TE_BLRn" : "no"
67 }
68
69 profilDatabankFound = False
70 evalueFound = False
71 MockConfigFile("config.cfg", dict)
72 try :
73 self._detectFeatureConfigChecker.check("config.cfg")
74 except ConfigException, e:
75 for msg in e.messages:
76 print msg
77 if (re.match("\[detect_features\] - No option 'te_hmm_profiles' in section: 'detect_features' whereas te_hmmer is set", msg)):
78 profilDatabankFound = True
79 if (re.match("\[detect_features\] - No option 'te_hmmer_evalue' in section: 'detect_features' whereas te_hmmer is set - Default value will be set", msg)):
80 evalueFound = True
81 self.assertTrue(profilDatabankFound)
82 self.assertTrue(evalueFound)
83 os.remove("config.cfg")
84
85
86 def testOptionsIfHmmProfilsSetAtNOInConfig (self):
87 profilDatabankFound = False
88 inputFormatFound = False
89 evalueFound = False
90 dict = {
91 "TE_HMMER" : "no"
92 }
93 MockConfigFile("config.cfg", dict)
94 try :
95 self._detectFeatureConfigChecker.check("config.cfg")
96 except ConfigException, e:
97 for msg in e.messages:
98 if (re.match(".+INFO \[detect_features\] - No option 'te_hmm_profiles' in section: 'detect_features' whereas te_hmmer is set", msg)):
99 profilDatabankFound = True
100 if (re.match(".+INFO \[detect_features\] - No option 'te_hmmer_evalue' in section: 'detect_features' whereas te_hmmer is set - Default value will be set", msg)):
101 evalueFound = True
102 self.assertFalse(profilDatabankFound)
103 self.assertFalse(inputFormatFound)
104 self.assertFalse(evalueFound)
105 os.remove("config.cfg")
106
107 def testTE_BLRnAndTE_hmmerAtNoInConfig (self):
108
109 dict = {
110 "TE_HMMER" : "no",
111 "TE_BLRn" : "no"
112 }
113
114 exceptionNotRaised = True
115 MockConfigFile("config.cfg", dict)
116 try :
117 self._detectFeatureConfigChecker.check("config.cfg")
118 except ConfigException:
119 exceptionNotRaised = False
120
121 self.assertTrue(exceptionNotRaised)
122
123 os.remove("config.cfg")
124
125 class MockConfigFile:
126
127 def __init__ (self, fileName, optionsDict):
128
129 self._fileName = fileName
130 config = open(fileName, "w");
131 config.write("[detect_features]\n")
132 for key in optionsDict.keys():
133 config.write(key + ":" + optionsDict[key] + "\n")
134 config.close()
135
136
137 if __name__ == "__main__":
138 unittest.main()