Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

when writing questions, try to convert them to strings

  • Loading branch information...
commit 6fe31bceeabc36199b35b323b8d6d908cebda5b1 1 parent 6150fac
@domenkozar authored
Showing with 17 additions and 4 deletions.
  1. +7 −4 mrbob/parsing.py
  2. +10 −0 mrbob/tests/test_parsing.py
View
11 mrbob/parsing.py
@@ -3,8 +3,8 @@
from collections import OrderedDict # NOQA
except ImportError: # pragma: no cover
from ordereddict import OrderedDict # NOQA
+import six
from six.moves import configparser
-from six import PY3
def nest_variables(variables):
@@ -23,7 +23,7 @@ def nest_variables(variables):
k = segments[-1]
if isinstance(location.get(k, None), dict):
raise ConfigurationError('Cannot assign "%s" to group "%s", subgroup is already used.' % (value, k))
- if PY3: # pragma: no cover
+ if six.PY3: # pragma: no cover
location[k] = value
else: # pragma: no cover
location[k] = value.decode('utf-8')
@@ -40,7 +40,7 @@ def parse_config(fs_config):
if section == 'questions':
config[section + "_order"] = [key[:-9] for key, value in items if key.endswith('.question')]
if section in ['variables', 'defaults']:
- if PY3: # pragma: no cover
+ if six.PY3: # pragma: no cover
config[section] = dict(items)
else: # pragma: no cover
config[section] = dict([(key, value.decode('utf-8')) for key, value in items])
@@ -55,7 +55,10 @@ def write_config(fs_config, section, data):
parser = configparser.SafeConfigParser(dict_type=OrderedDict)
parser.add_section(section)
for key, value in data.items():
- if not PY3: # pragma: no cover
+ if not isinstance(value, six.string_types):
+ value = str(value)
+
+ if not six.PY3: # pragma: no cover
value = value.encode('utf-8')
parser.set(section, key, value)
with open(fs_config, 'w') as f:
View
10 mrbob/tests/test_parsing.py
@@ -185,6 +185,16 @@ def test_utf8(self):
with codecs.open(self.tmpfile, 'r', 'utf-8') as f:
self.assertEqual(f.read(), six.u("[variables]\nfoo.bar = %s\n\n") % var_)
+ def test_non_str(self):
+ self.call_FUT(
+ 'variables',
+ {'foo': True},
+ )
+
+ with open(self.tmpfile) as f:
+ output = f.read()
+ self.assertTrue('\nfoo = True\n' in output)
+
class pretty_format_configTest(unittest.TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.