Salome HOME
Improve test procedure for source, patch and prepare commands
[tools/sat.git] / test / prepare / test_prepare.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 import shutil
23
24 # get execution path
25 testdir = os.path.dirname(os.path.realpath(__file__))
26 sys.path.append(os.path.join(testdir, '..', '..'))
27 sys.path.append(os.path.join(testdir, '..', '_testTools'))
28 sys.path.append(os.path.join(testdir, '..', '..','commands'))
29
30 import src
31
32 from tools import outRedirection
33
34 from salomeTools import Sat
35 import HTMLTestRunner
36
37 class TestPrepare(unittest.TestCase):
38     '''Test of the prepare command
39     '''
40
41     def test_prepare_dev(self):
42         '''Test the prepare command with a product in dev mode
43         '''
44         OK = 'KO'
45
46         appli = 'appli-test'
47         product_name = 'PRODUCT_DEV'
48
49         sat = Sat()
50                
51         sat.config(appli)
52         
53         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
54         expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
55         expected_text = 'HELLO WORLD\n'
56         
57         if os.path.exists(expected_src_dir):
58             shutil.rmtree(expected_src_dir)
59         
60         sat.prepare(appli + ' --product ' + product_name)
61         
62         f = open(expected_file_path, 'r')
63         text = f.readlines()[0]
64         if text == expected_text:
65             OK = 'OK'
66
67         # pyunit method to compare 2 str
68         self.assertEqual(OK, 'OK')
69
70     def test_prepare_all(self):
71         '''Test the prepare command with all products
72         '''
73         OK = 'KO'
74
75         appli = 'appli-test'
76         product_name = 'PRODUCT_DEV'
77
78         sat = Sat()
79         sat.config(appli)
80         
81         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
82         expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
83         expected_text = 'HELLO WORLD\n'
84         
85         if os.path.exists(expected_src_dir):
86             shutil.rmtree(expected_src_dir)
87         
88         sat.prepare(appli)
89         
90         f = open(expected_file_path, 'r')
91         text = f.readlines()[0]
92         if text == expected_text:
93             OK = 'OK'
94
95         # pyunit method to compare 2 str
96         self.assertEqual(OK, 'OK')
97
98     def test_prepare_option_sample_and_force(self):
99         '''Test the prepare command with all products
100         '''
101         OK = 'KO'
102
103         appli = 'appli-test'
104
105         sat = Sat()
106         sat.config(appli)
107        
108         try:
109             sat.prepare(appli + " --no_sample --force")
110             OK = 'OK'
111         except:
112             pass
113
114         # pyunit method to compare 2 str
115         self.assertEqual(OK, 'OK')
116
117     def test_description(self):
118         '''Test the sat -h prepare
119         '''        
120
121         OK = "KO"
122
123         import prepare
124         
125         if "The prepare command gets the sources" in prepare.description():
126             OK = "OK"
127
128         # pyunit method to compare 2 str
129         self.assertEqual(OK, "OK")
130
131 # test launch
132 if __name__ == '__main__':
133     HTMLTestRunner.main()