Merge lp:~veebers/autopilot/fix-config-contains-equals into lp:autopilot

Proposed by Christopher Lee
Status: Merged
Approved by: Leo Arias
Approved revision: 526
Merged at revision: 538
Proposed branch: lp:~veebers/autopilot/fix-config-contains-equals
Merge into: lp:autopilot
Diff against target: 57 lines (+19/-9)
2 files modified
autopilot/_config.py (+8/-8)
autopilot/tests/unit/test_config.py (+11/-1)
To merge this branch: bzr merge lp:~veebers/autopilot/fix-config-contains-equals
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Leo Arias (community) Approve
Review via email: mp+247540@code.launchpad.net

Commit message

Command line test config values can now contain the '=' character.

Description of the change

Command line test config values can now contain the '=' character.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

I like the new tests, and they all pass. Thanks.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/_config.py'
2--- autopilot/_config.py 2014-05-21 07:42:24 +0000
3+++ autopilot/_config.py 2015-01-25 21:35:22 +0000
4@@ -71,14 +71,14 @@
5
6 def __init__(self, config_string):
7 self._data = {}
8- for item in config_string.split(','):
9- if not item:
10- continue
11- parts = item.split('=')
12- if len(parts) == 1:
13- self._data[parts[0].lstrip()] = '1'
14- elif len(parts) == 2:
15- self._data[parts[0].lstrip()] = parts[1]
16+ config_items = (item for item in config_string.split(',') if item)
17+ for item in config_items:
18+ parts = item.split('=', 1)
19+ safe_key = parts[0].lstrip()
20+ if len(parts) == 1 and safe_key != '':
21+ self._data[safe_key] = '1'
22+ elif len(parts) == 2 and safe_key != '':
23+ self._data[safe_key] = parts[1]
24 else:
25 raise ValueError(
26 "Invalid configuration string '{}'".format(config_string)
27
28=== modified file 'autopilot/tests/unit/test_config.py'
29--- autopilot/tests/unit/test_config.py 2014-05-23 11:28:21 +0000
30+++ autopilot/tests/unit/test_config.py 2015-01-25 21:35:22 +0000
31@@ -51,6 +51,10 @@
32 d = config.ConfigDict('foo')
33 self.assertEqual(d['foo'], '1')
34
35+ def test_single_value_containing_equals_symbol(self):
36+ d = config.ConfigDict('foo=b=a')
37+ self.assertEqual(d['foo'], 'b=a')
38+
39 def test_multiple_simple_keys(self):
40 d = config.ConfigDict('foo,bar')
41 self.assertTrue('foo' in d)
42@@ -87,8 +91,14 @@
43 d = config.ConfigDict(' foo=bar, bar=baz')
44 self.assertEqual(set(d.keys()), {'foo', 'bar'})
45
46+ def test_raises_ValueError_on_blank_key(self):
47+ self.assertRaises(ValueError, lambda: config.ConfigDict('=,'))
48+
49+ def test_raises_ValueError_on_space_key(self):
50+ self.assertRaises(ValueError, lambda: config.ConfigDict(' =,'))
51+
52 def test_raises_ValueError_on_invalid_string(self):
53- self.assertRaises(ValueError, lambda: config.ConfigDict('f=b=c'))
54+ self.assertRaises(ValueError, lambda: config.ConfigDict('f,='))
55
56 def test_iter(self):
57 k = config.ConfigDict('foo').keys()

Subscribers

People subscribed via source and target branches