Salome HOME
fc231913313207f03ef4ddecdd1a3f9b64d56449
[tools/sat.git] / test / test_sat5_0 / job / test_job.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
26 class TestCase(unittest.TestCase):
27     """Test the job command"""
28
29     def test_010(self):
30         # Test the job command
31         OK = 'KO'
32         tmp_file = "/tmp/test.txt"
33
34         sat = Sat("-l " + tmp_file)
35         
36         # Execute the job command
37         sat.job("--jobs_config .test --name Job 1" )
38
39         ff = open(tmp_file, "r")
40         log_files = ff.readlines()
41         ff.close()
42         os.remove(tmp_file)
43         log_config = [line.replace("\n", "") for line in log_files if 'config.xml' in line]
44         
45         text = open(log_config[0], "r").read()
46
47         if "nb_proc" in text:
48             OK = 'OK'         
49         self.assertEqual(OK, 'OK')
50
51
52     def test_020(self):
53         # Test the job command with a failing command
54         OK = 'KO'
55         tmp_file = "/tmp/test.txt"
56
57         sat = Sat("-l " + tmp_file)
58         
59         # Execute the job command
60         res = sat.job("--jobs_config .test --name Job 4" )
61
62         if res == 1:
63             OK = 'OK'         
64         # pyunit method to compare 2 str
65         self.assertEqual(OK, 'OK')
66
67     def test_030(self):
68         # Test the job command with a wrong file configuration
69         OK = 'KO'
70         tmp_file = "/tmp/test.txt"
71
72         sat = Sat("-l " + tmp_file)
73         
74         # Execute the job command
75         res = sat.job("--jobs_config NOTEXIST --name Job 4" )
76
77         if res == 1:
78             OK = 'OK'         
79         self.assertEqual(OK, 'OK')
80
81     def test_040(self):
82         # Test the job command without --jobs_config option
83         OK = 'KO'
84         tmp_file = "/tmp/test.txt"
85
86         sat = Sat("-l " + tmp_file)
87         
88         # Execute the job command
89         res = sat.job("--name Job 4" )
90
91         if res == 1:
92             OK = 'OK'         
93         self.assertEqual(OK, 'OK')
94
95     def test_050(self):
96         # Test the job command without --jobs_config option
97         OK = 'KO'
98         tmp_file = "/tmp/test.txt"
99
100         sat = Sat("-l " + tmp_file)
101         
102         # Execute the job command
103         res = sat.job("--jobs_config .test --name NOTEXIST" )
104
105         if res == 1:
106             OK = 'OK'         
107         self.assertEqual(OK, 'OK')
108
109     def test_060(self):
110         # Test the sat -h job     
111         OK = "KO"
112
113         import job
114         
115         if "Executes the commands of the job defined in the jobs configuration file" in job.description():
116             OK = "OK"
117         self.assertEqual(OK, "OK")
118
119 # test launch
120 if __name__ == '__main__':
121     unittest.main()
122     pass