]> SALOME platform Git repositories - tools/sat.git/blob - test/job/test_job.py
Salome HOME
Implementation of the project notion, remove all pyconf regardings the products from...
[tools/sat.git] / test / job / test_job.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 import HTMLTestRunner
31
32 class TestJob(unittest.TestCase):
33     '''Test of the job command
34     '''
35
36     def test_job(self):
37         '''Test the job command
38         '''
39         OK = 'KO'
40         tmp_file = "/tmp/test.txt"
41
42         sat = Sat("-l " + tmp_file)
43         
44         # Execute the job command
45         sat.job("--jobs_config .test --name Job 1" )
46
47         ff = open(tmp_file, "r")
48         log_files = ff.readlines()
49         ff.close()
50         os.remove(tmp_file)
51         log_config = [line.replace("\n", "") for line in log_files if 'config.xml' in line]
52         
53         text = open(log_config[0], "r").read()
54
55         if "nb_proc" in text:
56             OK = 'OK'         
57         # pyunit method to compare 2 str
58         self.assertEqual(OK, 'OK')
59
60
61     def test_failing_job(self):
62         '''Test the job command with a failing command
63         '''
64         OK = 'KO'
65         tmp_file = "/tmp/test.txt"
66
67         sat = Sat("-l " + tmp_file)
68         
69         # Execute the job command
70         res = sat.job("--jobs_config .test --name Job 4" )
71
72         if res == 1:
73             OK = 'OK'         
74         # pyunit method to compare 2 str
75         self.assertEqual(OK, 'OK')
76
77     def test_file_conf_not_found(self):
78         '''Test the job command with a wrong file configuration
79         '''
80         OK = 'KO'
81         tmp_file = "/tmp/test.txt"
82
83         sat = Sat("-l " + tmp_file)
84         
85         # Execute the job command
86         res = sat.job("--jobs_config NOTEXIST --name Job 4" )
87
88         if res == 1:
89             OK = 'OK'         
90         # pyunit method to compare 2 str
91         self.assertEqual(OK, 'OK')
92
93     def test_no_option_jobs_config(self):
94         '''Test the job command without --jobs_config option
95         '''
96         OK = 'KO'
97         tmp_file = "/tmp/test.txt"
98
99         sat = Sat("-l " + tmp_file)
100         
101         # Execute the job command
102         res = sat.job("--name Job 4" )
103
104         if res == 1:
105             OK = 'OK'         
106         # pyunit method to compare 2 str
107         self.assertEqual(OK, 'OK')
108
109     def test_job_not_found(self):
110         '''Test the job command without --jobs_config 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.job("--jobs_config .test --name NOTEXIST" )
119
120         if res == 1:
121             OK = 'OK'         
122         # pyunit method to compare 2 str
123         self.assertEqual(OK, 'OK')
124
125     def test_description(self):
126         '''Test the sat -h job
127         '''        
128
129         OK = "KO"
130
131         import job
132         
133         if "Executes the commands of the job defined in the jobs configuration file" in job.description():
134             OK = "OK"
135
136         # pyunit method to compare 2 str
137         self.assertEqual(OK, "OK")
138
139 # test launch
140 if __name__ == '__main__':
141     HTMLTestRunner.main()