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
1=== modified file 'charmworld/lib/proof.py'
2--- charmworld/lib/proof.py 2013-11-01 18:37:41 +0000
3+++ charmworld/lib/proof.py 2013-11-06 19:18:02 +0000
4@@ -14,6 +14,7 @@
5 def check_config(charm, test_key, test_value):
6 type_map = {
7 'boolean': (bool,),
8+ 'float': (float,),
9 'int': (int, ),
10 'string': (str, unicode),
11 }
12@@ -31,10 +32,20 @@
13 'The charm has no option for: ' + test_key
14 )
15
16- # # The config key is a valid one for this charm. Check that the value
17- # # is of the right type.
18+ # The config key is a valid one for this charm. Check that the value
19+ # is of the right type.
20 specified_type = charm.options[test_key]['type']
21- valid_types = type_map[specified_type]
22+
23+ try:
24+ valid_types = type_map[specified_type]
25+ except KeyError:
26+ msg = "%s:%s is not a config type recognized."
27+ # Throw an error that we don't recognize the config type.
28+ raise ProofError(
29+ ['Looking at charm id: ' + charm._id],
30+ msg % (test_key, specified_type)
31+ )
32+
33 msg = "%s is not of type %s."
34 if type(test_value) not in valid_types:
35 raise ProofError(
36
37=== modified file 'charmworld/lib/tests/test_proof.py'
38--- charmworld/lib/tests/test_proof.py 2013-11-01 17:13:13 +0000
39+++ charmworld/lib/tests/test_proof.py 2013-11-06 19:18:02 +0000
40@@ -100,18 +100,84 @@
41 """Bundles might attempt to set a boolean config value string/int"""
42 charm = Mock()
43 charm.options = {
44- 'name': {
45+ 'accelerate': {
46 'type': 'boolean',
47- 'default': True,
48- }
49- }
50- charm._id = 'precise/test'
51-
52- with self.assertRaises(ProofError) as exc:
53- CharmProof.check_config(charm, 'name', 'test')
54-
55- self.assertEqual(
56- 'name is not of type boolean.',
57+ },
58+ }
59+ charm._id = 'precise/test'
60+
61+ with self.assertRaises(ProofError) as exc:
62+ CharmProof.check_config(charm, 'accelerate', 'test')
63+
64+ self.assertEqual(
65+ 'accelerate is not of type boolean.',
66+ exc.exception.msg
67+ )
68+ self.assertEqual(
69+ ['Looking at charm id: precise/test'],
70+ exc.exception.debug_info
71+ )
72+
73+ def test_check_config_int(self):
74+ """Bundles might attempt to set a int config value string"""
75+ charm = Mock()
76+ charm.options = {
77+ 'port': {
78+ 'type': 'int',
79+ },
80+ }
81+ charm._id = 'precise/test'
82+
83+ with self.assertRaises(ProofError) as exc:
84+ CharmProof.check_config(charm, 'port', 'test')
85+
86+ self.assertEqual(
87+ 'port is not of type int.',
88+ exc.exception.msg
89+ )
90+ self.assertEqual(
91+ ['Looking at charm id: precise/test'],
92+ exc.exception.debug_info
93+ )
94+
95+ def test_check_config_float(self):
96+ """Bundles might attempt to set a float config value string"""
97+ charm = Mock()
98+ charm.options = {
99+ 'some_count': {
100+ 'type': 'float',
101+ },
102+ }
103+ charm._id = 'precise/test'
104+
105+ with self.assertRaises(ProofError) as exc:
106+ CharmProof.check_config(charm, 'some_count', 'test')
107+
108+ self.assertEqual(
109+ 'some_count is not of type float.',
110+ exc.exception.msg
111+ )
112+ self.assertEqual(
113+ ['Looking at charm id: precise/test'],
114+ exc.exception.debug_info
115+ )
116+
117+ def test_check_config_is_unknown(self):
118+ """If we don't know the type then ignore it for now."""
119+ charm = Mock()
120+ charm.options = {
121+ 'some_count': {
122+ 'type': 'foo',
123+ },
124+ }
125+ charm._id = 'precise/test'
126+
127+ # Throws no errors.
128+ with self.assertRaises(ProofError) as exc:
129+ CharmProof.check_config(charm, 'some_count', 'test')
130+
131+ self.assertEqual(
132+ 'some_count:foo is not a config type recognized.',
133 exc.exception.msg
134 )
135 self.assertEqual(

Subscribers

People subscribed via source and target branches

to all changes: