Merge lp:~rharding/charmworld/allow-more-config-types into lp:charmworld

Proposed by Richard Harding
Status: Merged
Approved by: Richard Harding
Approved revision: 450
Merged at revision: 447
Proposed branch: lp:~rharding/charmworld/allow-more-config-types
Merge into: lp:charmworld
Diff against target: 135 lines (+91/-14)
2 files modified
charmworld/lib/proof.py (+14/-3)
charmworld/lib/tests/test_proof.py (+77/-11)
To merge this branch: bzr merge lp:~rharding/charmworld/allow-more-config-types
Reviewer Review Type Date Requested Status
Juju Gui Bot continuous-integration Approve
Charmworld Developers Pending
Review via email: mp+194209@code.launchpad.net

Commit message

Support float config type in proof.

- if we don't support validating it then ignore it for now
- add tests to each type we validate.

https://codereview.appspot.com/22370044/

R=bac

Description of the change

Support float config type in proof.

- if we don't support validating it then ignore it for now
- add tests to each type we validate.

https://codereview.appspot.com/22370044/

To post a comment you must log in.
Revision history for this message
Richard Harding (rharding) wrote :

Reviewers: mp+194209_code.launchpad.net,

Message:
Please take a look.

Description:
Support float config type in proof.

- if we don't support validating it then ignore it for now
- add tests to each type we validate.

https://code.launchpad.net/~rharding/charmworld/allow-more-config-types/+merge/194209

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/22370044/

Affected files (+85, -20 lines):
   A [revision details]
   M charmworld/lib/proof.py
   M charmworld/lib/tests/test_proof.py

Revision history for this message
Brad Crittenden (bac) wrote :

The code LGTM but I'm not sure about the choice to not throw an error on
unknown types.

https://codereview.appspot.com/22370044/diff/1/charmworld/lib/proof.py
File charmworld/lib/proof.py (right):

https://codereview.appspot.com/22370044/diff/1/charmworld/lib/proof.py#newcode43
charmworld/lib/proof.py:43: return
Shouldn't an invalid type be an error or at least a warning?

https://codereview.appspot.com/22370044/

449. By Richard Harding

Per review, make it an error vs ignore

450. By Richard Harding

lint

Revision history for this message
Juju Gui Bot (juju-gui-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmworld/lib/proof.py'
--- charmworld/lib/proof.py 2013-11-01 18:37:41 +0000
+++ charmworld/lib/proof.py 2013-11-06 19:18:02 +0000
@@ -14,6 +14,7 @@
14 def check_config(charm, test_key, test_value):14 def check_config(charm, test_key, test_value):
15 type_map = {15 type_map = {
16 'boolean': (bool,),16 'boolean': (bool,),
17 'float': (float,),
17 'int': (int, ),18 'int': (int, ),
18 'string': (str, unicode),19 'string': (str, unicode),
19 }20 }
@@ -31,10 +32,20 @@
31 'The charm has no option for: ' + test_key32 'The charm has no option for: ' + test_key
32 )33 )
3334
34 # # The config key is a valid one for this charm. Check that the value35 # The config key is a valid one for this charm. Check that the value
35 # # is of the right type.36 # is of the right type.
36 specified_type = charm.options[test_key]['type']37 specified_type = charm.options[test_key]['type']
37 valid_types = type_map[specified_type]38
39 try:
40 valid_types = type_map[specified_type]
41 except KeyError:
42 msg = "%s:%s is not a config type recognized."
43 # Throw an error that we don't recognize the config type.
44 raise ProofError(
45 ['Looking at charm id: ' + charm._id],
46 msg % (test_key, specified_type)
47 )
48
38 msg = "%s is not of type %s."49 msg = "%s is not of type %s."
39 if type(test_value) not in valid_types:50 if type(test_value) not in valid_types:
40 raise ProofError(51 raise ProofError(
4152
=== modified file 'charmworld/lib/tests/test_proof.py'
--- charmworld/lib/tests/test_proof.py 2013-11-01 17:13:13 +0000
+++ charmworld/lib/tests/test_proof.py 2013-11-06 19:18:02 +0000
@@ -100,18 +100,84 @@
100 """Bundles might attempt to set a boolean config value string/int"""100 """Bundles might attempt to set a boolean config value string/int"""
101 charm = Mock()101 charm = Mock()
102 charm.options = {102 charm.options = {
103 'name': {103 'accelerate': {
104 'type': 'boolean',104 'type': 'boolean',
105 'default': True,105 },
106 }106 }
107 }107 charm._id = 'precise/test'
108 charm._id = 'precise/test'108
109109 with self.assertRaises(ProofError) as exc:
110 with self.assertRaises(ProofError) as exc:110 CharmProof.check_config(charm, 'accelerate', 'test')
111 CharmProof.check_config(charm, 'name', 'test')111
112112 self.assertEqual(
113 self.assertEqual(113 'accelerate is not of type boolean.',
114 'name is not of type boolean.',114 exc.exception.msg
115 )
116 self.assertEqual(
117 ['Looking at charm id: precise/test'],
118 exc.exception.debug_info
119 )
120
121 def test_check_config_int(self):
122 """Bundles might attempt to set a int config value string"""
123 charm = Mock()
124 charm.options = {
125 'port': {
126 'type': 'int',
127 },
128 }
129 charm._id = 'precise/test'
130
131 with self.assertRaises(ProofError) as exc:
132 CharmProof.check_config(charm, 'port', 'test')
133
134 self.assertEqual(
135 'port is not of type int.',
136 exc.exception.msg
137 )
138 self.assertEqual(
139 ['Looking at charm id: precise/test'],
140 exc.exception.debug_info
141 )
142
143 def test_check_config_float(self):
144 """Bundles might attempt to set a float config value string"""
145 charm = Mock()
146 charm.options = {
147 'some_count': {
148 'type': 'float',
149 },
150 }
151 charm._id = 'precise/test'
152
153 with self.assertRaises(ProofError) as exc:
154 CharmProof.check_config(charm, 'some_count', 'test')
155
156 self.assertEqual(
157 'some_count is not of type float.',
158 exc.exception.msg
159 )
160 self.assertEqual(
161 ['Looking at charm id: precise/test'],
162 exc.exception.debug_info
163 )
164
165 def test_check_config_is_unknown(self):
166 """If we don't know the type then ignore it for now."""
167 charm = Mock()
168 charm.options = {
169 'some_count': {
170 'type': 'foo',
171 },
172 }
173 charm._id = 'precise/test'
174
175 # Throws no errors.
176 with self.assertRaises(ProofError) as exc:
177 CharmProof.check_config(charm, 'some_count', 'test')
178
179 self.assertEqual(
180 'some_count:foo is not a config type recognized.',
115 exc.exception.msg181 exc.exception.msg
116 )182 )
117 self.assertEqual(183 self.assertEqual(

Subscribers

People subscribed via source and target branches

to all changes: