Skip to content

Commit

Permalink
triggering error on required not set
Browse files Browse the repository at this point in the history
  • Loading branch information
jaesivsm committed Oct 22, 2017
1 parent 8bd6f3f commit 070630d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/test_the_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ def test_conf_from_obj(self):
self.assertEqual('a', tc.option)
tc.option = 1
self.assertEqual('1', tc.option)

def test_trigger_error_w_required(self):
metaconf = {'parameters': [
{'option': {'type': str, 'required': True}}],
'config_files': []}
self.assertRaises(ValueError,
TheConf, metaconf, cmd_line_opts=[])
tc = TheConf(metaconf, cmd_line_opts=['--option=stuff'])
self.assertEqual('stuff', tc.option)
2 changes: 1 addition & 1 deletion the_conf.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ parameters:
- nested:
- value:
type: int
required: true # default
required: false # default
- other_value:
type: bool
- int_value:
Expand Down
5 changes: 5 additions & 0 deletions the_conf/the_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def load(self):
else:
raise Exception('unknown order %r')

for path, value, param in self._get_path_val_param():
if value is node.NoValue and param.get('required'):
raise ValueError('loading finished and %r is not set'
% '.'.join(path))

def write(self, config_file=None):
if config_file is None and not self._config_files:
raise ValueError('no config file to write in')
Expand Down

0 comments on commit 070630d

Please sign in to comment.