Salome HOME
evite la construction de l'environnement launch, saus pour la commande sat check
[tools/sat.git] / test / test_020_debug.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 import initializeTest # set PATH etc for test
25
26 import src.debug as DBG # Easy print stderr (for DEBUG only)
27 import src.pyconf as PYF # 0.3.7
28
29 _EXAMPLES = {
30 1 : """\
31   messages:
32   [
33     {
34       stream : "sys.stderr" # modified
35       message: 111 # modified
36       name: 'Harry'
37     }
38     {
39       stream : $messages[0].stream
40       message: 1.23e4 # modified do not work 0.3.7
41       name: 'Ruud'
42     }
43     {
44       stream : "HELLO " + $messages[0].stream
45       message: 'Bienvenue'
46       name: "Yves"
47     }
48   ]
49 """,
50
51 2 : """\
52   aa: 111
53   bb: $aa + 222
54 """,
55
56 3 : """\
57   aa: Yves
58   bb: "Herve" # avoid Hervé -> 'utf8' codec can't decode byte
59 """,
60
61 4 : """\
62   aa: Yves
63   bb: "Hervé" # avoid Hervé -> 'utf8' codec can't decode byte
64 """,
65
66
67 }
68
69
70 class TestCase(unittest.TestCase):
71   "Test the debug.py"""
72   
73   def test_000(self):
74     # one shot setUp() for this TestCase
75     # DBG.push_debug(True)
76     # SAT.setNotLocale() # test english
77     return
78     
79   def test_005(self):
80     res = DBG.getLocalEnv()
81     self.assertTrue(len(res.split()) > 0)
82     self.assertTrue("USER :" in res)
83     self.assertTrue("LANG :" in res)
84        
85   def test_010(self):
86     inStream = DBG.InStream(_EXAMPLES[1])
87     self.assertEqual(inStream.getvalue(), _EXAMPLES[1])
88     cfg = PYF.Config(inStream)
89     self.assertEqual(len(cfg.messages), 3)
90     outStream = DBG.OutStream()
91     DBG.saveConfigStd(cfg, outStream)
92     res = outStream.value
93     DBG.write("test_010 cfg std", res)
94     self.assertTrue("messages :" in res)
95     self.assertTrue("'sys.stderr'" in res)
96     
97   def test_020(self):
98     inStream = DBG.InStream(_EXAMPLES[2])
99     cfg = PYF.Config(inStream)
100     res = DBG.getStrConfigDbg(cfg)
101     DBG.write("test_020 cfg dbg", res)
102     ress = res.split("\n")
103     self.assertTrue(".aa" in ress[0])
104     self.assertTrue(": '111'" in ress[0])
105     self.assertTrue(".bb" in ress[1])
106     self.assertTrue(": $aa + 222 " in ress[1])
107     self.assertTrue("--> '333'" in ress[1])
108     
109   def test_025(self):
110     inStream = DBG.InStream(_EXAMPLES[1])
111     cfg = PYF.Config(inStream)
112     outStream = DBG.OutStream()
113     DBG.saveConfigDbg(cfg, outStream)
114     res = outStream.value
115     DBG.write("test_025 cfg dbg", res)
116     for i in range(len(cfg.messages)):
117       self.assertTrue("messages[%i].name" % i in res)
118     self.assertTrue("--> 'HELLO sys.stderr'" in res)
119
120       
121   def test_999(self):
122     # one shot tearDown() for this TestCase
123     # SAT.setLocale() # end test english
124     # DBG.pop_debug()
125     return
126     
127 if __name__ == '__main__':
128     unittest.main(exit=False)
129     pass
130