3 # Copyright (C) 2010-2012 CEA/DEN
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.
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.
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
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'))
29 from salomeTools import Sat
30 from tools import outRedirection
33 class TestJobs(unittest.TestCase):
34 '''Test of the jobs command
38 '''Test the jobs command
41 tmp_file = "/tmp/test.txt"
43 sat = Sat("-l " + tmp_file)
45 # Execute the jobs command
46 sat.jobs("--name .test --publish" )
48 ff = open(tmp_file, "r")
49 log_files = ff.readlines()
52 log_jobs = [line.replace("\n", "") for line in log_files if 'jobs.xml' in line]
54 text = open(log_jobs[0], "r").read()
57 "Establishing connection with all the machines",
63 for exp_res in expected_res:
64 if exp_res not in text:
70 # pyunit method to compare 2 str
71 self.assertEqual(OK, 'OK')
73 def test_jobs_only_jobs(self):
74 '''Test the jobs command with option --only_jobs
77 tmp_file = "/tmp/test.txt"
79 sat = Sat("-l " + tmp_file)
81 # Execute the jobs command
82 sat.jobs("--name .test --publish --only_jobs Job 1" )
84 ff = open(tmp_file, "r")
85 log_files = ff.readlines()
88 log_jobs = [line.replace("\n", "") for line in log_files if 'jobs.xml' in line]
90 text = open(log_jobs[0], "r").read()
93 "Establishing connection with all the machines",
99 for exp_res in expected_res:
100 if exp_res not in text:
106 # pyunit method to compare 2 str
107 self.assertEqual(OK, 'OK')
109 def test_no_option_name(self):
110 '''Test the jobs command without --name option
113 tmp_file = "/tmp/test.txt"
115 sat = Sat("-l " + tmp_file)
117 # Execute the job command
122 # pyunit method to compare 2 str
123 self.assertEqual(OK, 'OK')
125 def test_file_conf_not_found(self):
126 '''Test the jobs command with a wrong file configuration
129 tmp_file = "/tmp/test.txt"
131 sat = Sat("-l " + tmp_file)
133 # Execute the job command
134 res = sat.jobs("--name NOTEXIST" )
138 # pyunit method to compare 2 str
139 self.assertEqual(OK, 'OK')
141 def test_option_list(self):
142 '''Test the display of the right value of "sat jobs --list"
148 my_out = outRedirection()
150 # The command to test
154 # stop output redirection
155 my_out.end_redirection()
158 res = my_out.read_results()
161 if "ERROR" not in res:
164 # pyunit method to compare 2 str
165 self.assertEqual(OK, "OK")
167 def test_description(self):
168 '''Test the sat -h jobs
175 if "The jobs command launches maintenances that are described in the dedicated jobs configuration file." in jobs.description():
178 # pyunit method to compare 2 str
179 self.assertEqual(OK, "OK")
182 if __name__ == '__main__':
183 HTMLTestRunner.main()