From c06659012b9e723c98259e4ef3c2118bc330dcf0 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 3 Jul 2013 21:56:19 +0200 Subject: [PATCH] Config: __str__ raise if no str/unicode value --- test/test_config.py | 15 ++++++++++++++- tiramisu/config.py | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/test/test_config.py b/test/test_config.py index 6c6f91d..61ec52b 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -1,10 +1,11 @@ +# -*- coding: utf-8 -*- #this test is much more to test that **it's there** and answers attribute access import autopath from py.test import raises from tiramisu.config import Config from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \ - BoolOption, OptionDescription + BoolOption, UnicodeOption, OptionDescription def make_description(): @@ -112,3 +113,15 @@ def test_information_config(): string = 'some informations' config.impl_set_information('info', string) assert config.impl_get_information('info') == string + + +def test_information_display(): + g1 = IntOption('g1', '', 1) + g2 = StrOption('g2', '', 'héhé') + g3 = UnicodeOption('g3', '', u'héhé') + g4 = BoolOption('g4', '', True) + g5 = StrOption('g5', '') + d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5]) + root = OptionDescription('root', '', [d1]) + config = Config(root) + str(config.od) diff --git a/tiramisu/config.py b/tiramisu/config.py index eb4dd77..8a0d84d 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -135,9 +135,11 @@ class SubConfig(BaseInformation): for name, grp in self.iter_groups(): lines.append("[{0}]".format(name)) for name, value in self: - value = value.encode(default_encoding) try: lines.append("{0} = {1}".format(name, value)) + except UnicodeEncodeError: + lines.append("{0} = {1}".format(name, + value.encode(default_encoding))) except PropertiesOptionError: pass return '\n'.join(lines)