[test] Fix broken unittest_configuration.py:ConfigurationTC.test_round_trip

authorAnthony Truchet <anthony.truchet@logilab.fr>
changeset0b5866b2bd8e
branchdefault
phasedraft
hiddenyes
parent revision#e9fc9f452231 merge default heads
child revision#187621e2ccca [configuration] closes #185648 : load options in config file order, #ad0225438f08 [configuration] option should be processed in file order, not declaration order.
files modified by this revision
test/unittest_configuration.py
# HG changeset patch
# User Anthony Truchet <anthony.truchet@logilab.fr>
# Date 1382715046 -7200
# Fri Oct 25 17:30:46 2013 +0200
# Node ID 0b5866b2bd8e258853a556c351e336fdc4b95156
# Parent e9fc9f4522317c21d543a41a4f630d5fb3142e8f
[test] Fix broken unittest_configuration.py:ConfigurationTC.test_round_trip

diff --git a/test/unittest_configuration.py b/test/unittest_configuration.py
@@ -16,10 +16,11 @@
1  # You should have received a copy of the GNU Lesser General Public License along
2  # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
3  import tempfile
4  import os
5  from os.path import join, dirname, abspath
6 +import re
7 
8  from cStringIO import StringIO
9  from sys import version_info
10 
11  from logilab.common.testlib import TestCase, unittest_main
@@ -30,17 +31,17 @@
12 
13  DATA = join(dirname(abspath(__file__)), 'data')
14 
15  OPTIONS = [('dothis', {'type':'yn', 'action': 'store', 'default': True, 'metavar': '<y or n>'}),
16             ('value', {'type': 'string', 'metavar': '<string>', 'short': 'v'}),
17 -           ('multiple', {'type': 'csv', 'default': ('yop', 'yep'),
18 +           ('multiple', {'type': 'csv', 'default': ['yop', 'yep'],
19                           'metavar': '<comma separated values>',
20                           'help': 'you can also document the option'}),
21             ('number', {'type': 'int', 'default':2, 'metavar':'<int>', 'help': 'boom'}),
22             ('choice', {'type': 'choice', 'default':'yo', 'choices': ('yo', 'ye'),
23                         'metavar':'<yo|ye>'}),
24 -           ('multiple-choice', {'type': 'multiple_choice', 'default':('yo', 'ye'),
25 +           ('multiple-choice', {'type': 'multiple_choice', 'default':['yo', 'ye'],
26                                  'choices': ('yo', 'ye', 'yu', 'yi', 'ya'),
27                                  'metavar':'<yo|ye>'}),
28             ('named', {'type':'named', 'default':Method('get_named'),
29                        'metavar': '<key=val>'}),
30 
@@ -61,14 +62,14 @@
31 
32      def test_default(self):
33          cfg = self.cfg
34          self.assertEqual(cfg['dothis'], True)
35          self.assertEqual(cfg['value'], None)
36 -        self.assertEqual(cfg['multiple'], ('yop', 'yep'))
37 +        self.assertEqual(cfg['multiple'], ['yop', 'yep'])
38          self.assertEqual(cfg['number'], 2)
39          self.assertEqual(cfg['choice'], 'yo')
40 -        self.assertEqual(cfg['multiple-choice'], ('yo', 'ye'))
41 +        self.assertEqual(cfg['multiple-choice'], ['yo', 'ye'])
42          self.assertEqual(cfg['named'], {'key': 'val'})
43 
44      def test_base(self):
45          cfg = self.cfg
46          cfg.set_option('number', '0')
@@ -205,13 +206,16 @@
47      def test_roundtrip(self):
48          cfg = self.cfg
49          f = tempfile.mktemp()
50          stream = open(f, 'w')
51          try:
52 +            self.cfg['dothis']=False
53 +            self.cfg['multiple']= ["toto", "tata"]
54 +            self.cfg['number']=3
55              cfg.generate_config(stream)
56              stream.close()
57 -            new_cfg = MyConfiguration(name='testloop', options=OPTIONS)
58 +            new_cfg = MyConfiguration(name='test', options=OPTIONS)
59              new_cfg.load_file_configuration(f)
60              self.assertEqual(cfg['dothis'], new_cfg['dothis'])
61              self.assertEqual(cfg['multiple'], new_cfg['multiple'])
62              self.assertEqual(cfg['number'], new_cfg['number'])
63              self.assertEqual(cfg['choice'], new_cfg['choice'])
@@ -232,22 +236,23 @@
64          # at least in python 2.4.2 the output is:
65          # '  -v <string>, --value=<string>'
66          # it is not unlikely some optik/optparse versions do print -v<string>
67          # so accept both
68          help = help.replace(' -v <string>, ', ' -v<string>, ')
69 +        help = re.sub('[ ]*(\r?\n)', '\\1', help)
70          USAGE = """Usage: Just do it ! (tm)
71 
72  Options:
73    -h, --help            show this help message and exit
74 -  --dothis=<y or n>     
75 +  --dothis=<y or n>
76    -v<string>, --value=<string>
77    --multiple=<comma separated values>
78                          you can also document the option [current: yop,yep]
79    --number=<int>        boom [current: 2]
80 -  --choice=<yo|ye>      
81 +  --choice=<yo|ye>
82    --multiple-choice=<yo|ye>
83 -  --named=<key=val>     
84 +  --named=<key=val>
85 
86    Agroup:
87      --diffgroup=<key=val>
88 
89    Bonus: