##// END OF EJS Templates
fix type=str->unicode in argparse kv loader...
MinRK -
Show More
@@ -621,9 +621,9 b' class KVArgParseConfigLoader(ArgParseConfigLoader):'
621 621 else:
622 622 nargs = None
623 623 if len(key) is 1:
624 paa('-'+key, '--'+key, type=str, dest=value, nargs=nargs)
624 paa('-'+key, '--'+key, type=unicode, dest=value, nargs=nargs)
625 625 else:
626 paa('--'+key, type=str, dest=value, nargs=nargs)
626 paa('--'+key, type=unicode, dest=value, nargs=nargs)
627 627 for key, (value, help) in flags.iteritems():
628 628 if key in self.aliases:
629 629 #
@@ -35,6 +35,7 b' from IPython.config.loader import ('
35 35 PyFileConfigLoader,
36 36 KeyValueConfigLoader,
37 37 ArgParseConfigLoader,
38 KVArgParseConfigLoader,
38 39 ConfigError
39 40 )
40 41
@@ -117,9 +118,10 b' class TestArgParseCL(TestCase):'
117 118
118 119
119 120 class TestKeyValueCL(TestCase):
121 klass = KeyValueConfigLoader
120 122
121 123 def test_basic(self):
122 cl = KeyValueConfigLoader()
124 cl = self.klass()
123 125 argv = ['--'+s.strip('c.') for s in pyfile.split('\n')[2:-1]]
124 126 with mute_warn():
125 127 config = cl.load_config(argv)
@@ -130,7 +132,7 b' class TestKeyValueCL(TestCase):'
130 132 self.assertEquals(config.D.C.value, 'hi there')
131 133
132 134 def test_extra_args(self):
133 cl = KeyValueConfigLoader()
135 cl = self.klass()
134 136 with mute_warn():
135 137 config = cl.load_config(['--a=5', 'b', '--c=10', 'd'])
136 138 self.assertEquals(cl.extra_args, ['b', 'd'])
@@ -141,7 +143,7 b' class TestKeyValueCL(TestCase):'
141 143 self.assertEquals(cl.extra_args, ['--a=5', '--c=10'])
142 144
143 145 def test_unicode_args(self):
144 cl = KeyValueConfigLoader()
146 cl = self.klass()
145 147 argv = [u'--a=épsîlön']
146 148 with mute_warn():
147 149 config = cl.load_config(argv)
@@ -154,11 +156,21 b' class TestKeyValueCL(TestCase):'
154 156 except (TypeError, UnicodeEncodeError):
155 157 raise SkipTest("sys.stdin.encoding can't handle 'é'")
156 158
157 cl = KeyValueConfigLoader()
159 cl = self.klass()
158 160 with mute_warn():
159 161 config = cl.load_config([barg])
160 162 self.assertEquals(config.a, u'é')
161 163
164 def test_unicode_alias(self):
165 cl = self.klass()
166 argv = [u'--a=épsîlön']
167 with mute_warn():
168 config = cl.load_config(argv, aliases=dict(a='A.a'))
169 self.assertEquals(config.A.a, u'épsîlön')
170
171
172 class TestArgParseKVCL(TestKeyValueCL):
173 klass = KVArgParseConfigLoader
162 174
163 175 class TestConfig(TestCase):
164 176
General Comments 0
You need to be logged in to leave comments. Login now