Skip to content

Commit

Permalink
Enforce that config.String gets a value
Browse files Browse the repository at this point in the history
This makes it more consistent with the other config parsers. If the
string value should truly be optional, the user should explicitly mark
it as such by wrapping it with config.Optional.
  • Loading branch information
spladug committed Jul 18, 2016
1 parent addc889 commit f1737ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions baseplate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def __str__(self): # pragma: nocover

def String(text):
"""A raw string."""
if not text:
raise ValueError("no value specified")
return text


Expand Down
6 changes: 5 additions & 1 deletion tests/unit/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def test_parse_string(self):
result = config.String("whatever")
self.assertEqual(result, "whatever")

def test_empty_string_not_ok(self):
with self.assertRaises(ValueError):
config.String("")


class IntegerTests(unittest.TestCase):
def test_parse_integer_valid(self):
Expand Down Expand Up @@ -189,7 +193,7 @@ def test_simple_config(self):
},

"noo": {
"bar": config.String,
"bar": config.Optional(config.String, default=""),
},

"deep": {
Expand Down

0 comments on commit f1737ea

Please sign in to comment.