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