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