Salome HOME
suppresion d'un log
[tools/sat.git] / test / jobs / test_jobs.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 import unittest
20 import os
21 import sys
22
23 # get execution path
24 testdir = os.path.dirname(os.path.realpath(__file__))
25 sys.path.append(os.path.join(testdir, '..', '..'))
26 sys.path.append(os.path.join(testdir, '..', '_testTools'))
27 sys.path.append(os.path.join(testdir, '..', '..','commands'))
28
29 from salomeTools import Sat
30 from tools import outRedirection
31 import HTMLTestRunner
32
33 class TestJobs(unittest.TestCase):
34     '''Test of the jobs command
35     '''
36
37     def test_jobs(self):
38         '''Test the jobs command
39         '''
40         OK = 'KO'
41         tmp_file = "/tmp/test.txt"
42
43         sat = Sat("-l " + tmp_file)
44         
45         # Execute the jobs command
46         sat.jobs("--name .test --publish" )
47
48         ff = open(tmp_file, "r")
49         log_files = ff.readlines()
50         ff.close()
51         os.remove(tmp_file)
52         log_jobs = [line.replace("\n", "") for line in log_files if 'jobs.xml' in line]
53         
54         text = open(log_jobs[0], "r").read()
55         
56         expected_res = [
57         "Establishing connection with all the machines",
58         "Executing the jobs",
59         "Results for job"
60         ]
61         
62         res = 0
63         for exp_res in expected_res:
64             if exp_res not in text:
65                 res += 1
66         
67         if res == 0:
68             OK = 'OK'
69                          
70         # pyunit method to compare 2 str
71         self.assertEqual(OK, 'OK')
72
73     def test_jobs_only_jobs(self):
74         '''Test the jobs command with option --only_jobs
75         '''
76         OK = 'KO'
77         tmp_file = "/tmp/test.txt"
78
79         sat = Sat("-l " + tmp_file)
80         
81         # Execute the jobs command
82         sat.jobs("--name .test --publish --only_jobs Job 1" )
83
84         ff = open(tmp_file, "r")
85         log_files = ff.readlines()
86         ff.close()
87         os.remove(tmp_file)
88         log_jobs = [line.replace("\n", "") for line in log_files if 'jobs.xml' in line]
89         
90         text = open(log_jobs[0], "r").read()
91         
92         expected_res = [
93         "Establishing connection with all the machines",
94         "Executing the jobs",
95         "Results for job"
96         ]
97         
98         res = 0
99         for exp_res in expected_res:
100             if exp_res not in text:
101                 res += 1
102         
103         if res == 0:
104             OK = 'OK'
105                          
106         # pyunit method to compare 2 str
107         self.assertEqual(OK, 'OK')
108
109     def test_no_option_name(self):
110         '''Test the jobs command without --name option
111         '''
112         OK = 'KO'
113         tmp_file = "/tmp/test.txt"
114
115         sat = Sat("-l " + tmp_file)
116         
117         # Execute the job command
118         res = sat.jobs()
119
120         if res == 1:
121             OK = 'OK'         
122         # pyunit method to compare 2 str
123         self.assertEqual(OK, 'OK')
124         
125     def test_file_conf_not_found(self):
126         '''Test the jobs command with a wrong file configuration
127         '''
128         OK = 'KO'
129         tmp_file = "/tmp/test.txt"
130
131         sat = Sat("-l " + tmp_file)
132         
133         # Execute the job command
134         res = sat.jobs("--name NOTEXIST" )
135
136         if res == 1:
137             OK = 'OK'         
138         # pyunit method to compare 2 str
139         self.assertEqual(OK, 'OK')
140
141     def test_option_list(self):
142         '''Test the display of the right value of "sat jobs --list"
143         '''
144         
145         OK = "KO"
146
147         # output redirection
148         my_out = outRedirection()
149
150         # The command to test
151         sat = Sat()
152         sat.jobs('--list')
153
154         # stop output redirection
155         my_out.end_redirection()
156
157         # get results
158         res = my_out.read_results()
159
160         # get results
161         if "ERROR" not in res:
162             OK = "OK"
163
164         # pyunit method to compare 2 str
165         self.assertEqual(OK, "OK")
166
167     def test_description(self):
168         '''Test the sat -h jobs
169         '''        
170
171         OK = "KO"
172
173         import jobs
174         
175         if "The jobs command launches maintenances that are described in the dedicated jobs configuration file." in jobs.description():
176             OK = "OK"
177
178         # pyunit method to compare 2 str
179         self.assertEqual(OK, "OK")
180
181 # test launch
182 if __name__ == '__main__':
183     HTMLTestRunner.main()