Salome HOME
style: black format
[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
28 class TestCase(unittest.TestCase):
29     "Test the jobs command" ""
30
31     def test_010(self):
32         # Test the jobs command
33         OK = "KO"
34         tmp_file = "/tmp/test.txt"
35
36         sat = Sat("-l " + tmp_file)
37
38         # Execute the jobs command
39         sat.jobs("--name .test --publish")
40
41         ff = open(tmp_file, "r")
42         log_files = ff.readlines()
43         ff.close()
44         os.remove(tmp_file)
45         log_jobs = [line.replace("\n", "") for line in log_files if "jobs.xml" in line]
46
47         text = open(log_jobs[0], "r").read()
48
49         expected_res = [
50             "Establishing connection with all the machines",
51             "Executing the jobs",
52             "Results for job",
53         ]
54
55         res = 0
56         for exp_res in expected_res:
57             if exp_res not in text:
58                 res += 1
59
60         if res == 0:
61             OK = "OK"
62         self.assertEqual(OK, "OK")
63
64     def test_020(self):
65         # Test the jobs command with option --only_jobs
66         OK = "KO"
67         tmp_file = "/tmp/test.txt"
68
69         sat = Sat("-l " + tmp_file)
70
71         # Execute the jobs command
72         sat.jobs("--name .test --publish --only_jobs Job 1")
73
74         ff = open(tmp_file, "r")
75         log_files = ff.readlines()
76         ff.close()
77         os.remove(tmp_file)
78         log_jobs = [line.replace("\n", "") for line in log_files if "jobs.xml" in line]
79
80         text = open(log_jobs[0], "r").read()
81
82         expected_res = [
83             "Establishing connection with all the machines",
84             "Executing the jobs",
85             "Results for job",
86         ]
87
88         res = 0
89         for exp_res in expected_res:
90             if exp_res not in text:
91                 res += 1
92
93         if res == 0:
94             OK = "OK"
95         self.assertEqual(OK, "OK")
96
97     def test_030(self):
98         # Test the jobs command without --name option
99         OK = "KO"
100         tmp_file = "/tmp/test.txt"
101
102         sat = Sat("-l " + tmp_file)
103
104         # Execute the job command
105         res = sat.jobs()
106
107         if res == 1:
108             OK = "OK"
109         self.assertEqual(OK, "OK")
110
111     def test_040(self):
112         # Test the jobs command with a wrong file configuration
113         OK = "KO"
114         tmp_file = "/tmp/test.txt"
115
116         sat = Sat("-l " + tmp_file)
117
118         # Execute the job command
119         res = sat.jobs("--name NOTEXIST")
120
121         if res == 1:
122             OK = "OK"
123         self.assertEqual(OK, "OK")
124
125     def test_050(self):
126         # Test the display of the right value of 'sat jobs --list'
127         OK = "KO"
128
129         # output redirection
130         my_out = outRedirection()
131
132         # The command to test
133         sat = Sat()
134         sat.jobs("--list")
135
136         # stop output redirection
137         my_out.end_redirection()
138
139         # get results
140         res = my_out.read_results()
141
142         # get results
143         if "ERROR" not in res:
144             OK = "OK"
145         self.assertEqual(OK, "OK")
146
147     def test_060(self):
148         # Test the sat -h jobs
149         OK = "KO"
150
151         import jobs
152
153         if (
154             "The jobs command launches maintenances that are described in the dedicated jobs configuration file."
155             in jobs.description()
156         ):
157             OK = "OK"
158         self.assertEqual(OK, "OK")
159
160
161 # test launch
162 if __name__ == "__main__":
163     unittest.main()
164     pass