Salome HOME
style: black format
[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     2: """\
51   aa: 111
52   bb: $aa + 222
53 """,
54     3: """\
55   aa: Yves
56   bb: "Herve" # avoid Hervé -> 'utf8' codec can't decode byte
57 """,
58     4: """\
59   aa: Yves
60   bb: "Hervé" # avoid Hervé -> 'utf8' codec can't decode byte
61 """,
62 }
63
64
65 class TestCase(unittest.TestCase):
66     "Test the debug.py" ""
67
68     def test_000(self):
69         # one shot setUp() for this TestCase
70         # DBG.push_debug(True)
71         # SAT.setNotLocale() # test english
72         return
73
74     def test_005(self):
75         res = DBG.getLocalEnv()
76         self.assertTrue(len(res.split()) > 0)
77         self.assertTrue("USER :" in res)
78         self.assertTrue("LANG :" in res)
79
80     def test_010(self):
81         inStream = DBG.InStream(_EXAMPLES[1])
82         self.assertEqual(inStream.getvalue(), _EXAMPLES[1])
83         cfg = PYF.Config(inStream)
84         self.assertEqual(len(cfg.messages), 3)
85         outStream = DBG.OutStream()
86         DBG.saveConfigStd(cfg, outStream)
87         res = outStream.value
88         DBG.write("test_010 cfg std", res)
89         self.assertTrue("messages :" in res)
90         self.assertTrue("'sys.stderr'" in res)
91
92     def test_020(self):
93         inStream = DBG.InStream(_EXAMPLES[2])
94         cfg = PYF.Config(inStream)
95         res = DBG.getStrConfigDbg(cfg)
96         DBG.write("test_020 cfg dbg", res)
97         ress = res.split("\n")
98         self.assertTrue(".aa" in ress[0])
99         self.assertTrue(": '111'" in ress[0])
100         self.assertTrue(".bb" in ress[1])
101         self.assertTrue(": $aa + 222 " in ress[1])
102         self.assertTrue("--> '333'" in ress[1])
103
104     def test_025(self):
105         inStream = DBG.InStream(_EXAMPLES[1])
106         cfg = PYF.Config(inStream)
107         outStream = DBG.OutStream()
108         DBG.saveConfigDbg(cfg, outStream)
109         res = outStream.value
110         DBG.write("test_025 cfg dbg", res)
111         for i in range(len(cfg.messages)):
112             self.assertTrue("messages[%i].name" % i in res)
113         self.assertTrue("--> 'HELLO sys.stderr'" in res)
114
115     def test_999(self):
116         # one shot tearDown() for this TestCase
117         # SAT.setLocale() # end test english
118         # DBG.pop_debug()
119         return
120
121
122 if __name__ == "__main__":
123     unittest.main(exit=False)
124     pass