Skip to content

Commit

Permalink
Fix printing of keys with non-string values
Browse files Browse the repository at this point in the history
When trying to print a key which has a non-string value
(e.g. bool or int), TypeError exception is raised. This
is caused by the fact, that ensure_type() function accepts
string values, but parsed values are passed (i.e. False
instead of 'False' or 12 instead of '12' and so on).

Change-Id: I10f5e60994bc34288f15af07d2d255ace3755b57
Closes-Bug: #1243263
  • Loading branch information
Roman Podolyaka committed Oct 22, 2013
1 parent d99f3c8 commit a666935
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion os_apply_config/apply_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def print_key(
else:
raise exc.ConfigException(
'key %s does not exist in %s' % (key, config_path))
value_types.ensure_type(config, type_name)
value_types.ensure_type(str(config), type_name)
print(str(config))


Expand Down
10 changes: 10 additions & 0 deletions os_apply_config/tests/test_apply_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# config for example tree
CONFIG = {
"x": "foo",
"y": False,
"database": {
"url": "sqlite:///blah"
}
Expand Down Expand Up @@ -90,6 +91,15 @@ def test_print_key(self):
self.stdout.read().strip())
self.assertEqual('', self.logger.output)

def test_print_non_string_key(self):
self.assertEqual(0, apply_config.main(
['os-apply-config.py', '--metadata', self.path, '--key',
'y', '--type', 'raw']))
self.stdout.seek(0)
self.assertEqual(str(CONFIG['y']),
self.stdout.read().strip())
self.assertEqual('', self.logger.output)

def test_print_key_missing(self):
self.assertEqual(1, apply_config.main(
['os-apply-config.py', '--metadata', self.path, '--key',
Expand Down

0 comments on commit a666935

Please sign in to comment.