Skip to content

Commit

Permalink
Merge pull request #6 from boegel/stop_worrying_and_start_loving_conf…
Browse files Browse the repository at this point in the history
…igfiles

fix take_action for add* typed values
  • Loading branch information
stdweird committed Apr 21, 2015
2 parents 8f59d49 + 57d0e24 commit 9edb250
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/vsc/utils/generaloption.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ def take_action(self, action, dest, opt, value, values, parser):
if action in ("add", "add_first", "add_flex",):
# determine type from lvalue
# set default first
values.ensure_value(dest, type(value)())
default = getattr(values, dest)
default = getattr(parser.get_default_values(), dest, None)
if default is None:
default = type(value)()
if not (hasattr(default, '__add__') and
(hasattr(default, '__neg__') or hasattr(default, '__getslice__'))):
msg = "Unsupported type %s for action %s (requires + and one of negate or slice)"
Expand Down
6 changes: 2 additions & 4 deletions test/generaloption.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,14 @@ def test_ext_add_multi(self):
topt = TestOption1(go_args=args, envvar_prefix='TEST')
self.assertEqual(topt.options.ext_add_default, 'nowtwo')

# environment overrides config file
os.environ['TEST_EXT_ADD_DEFAULT'] = 'three'
topt = TestOption1(go_args=args, envvar_prefix='TEST')
self.assertEqual(topt.options.ext_add_default, 'nowthree')

# command line overrides environment + config file, last value wins
args.extend(['--ext-add-default=four', '--ext-add-default=five'])
topt = TestOption1(go_args=args, envvar_prefix='TEST')
#self.assertEqual(topt.options.ext_add_default, 'nowthreefourfive')
self.assertEqual(topt.options.ext_add_default, 'nowfive')
del os.environ['TEST_EXT_ADD_DEFAULT']

Expand All @@ -376,7 +377,6 @@ def test_ext_add_multi(self):
'--ext-add-list-default=seven,eight',
])
topt = TestOption1(go_args=args, envvar_prefix='TEST')
#self.assertEqual(topt.options.ext_add_list_default, ['now', 'four', 'five', 'six', 'seven', 'eight'])
self.assertEqual(topt.options.ext_add_list_default, ['now', 'seven', 'eight'])
del os.environ['TEST_EXT_ADD_LIST_DEFAULT']

Expand All @@ -397,7 +397,6 @@ def test_ext_add_multi(self):
'--ext-add-list-flex=,last',
])
topt = TestOption1(go_args=args, envvar_prefix='TEST')
#self.assertEqual(topt.options.ext_add_list_flex, ['seven', 'six', 'four', 'x', 'y', 'five', 'eight', 'last'])
self.assertEqual(topt.options.ext_add_list_flex, ['x', 'y', 'last'])
del os.environ['TEST_EXT_ADD_LIST_FLEX']

Expand All @@ -419,7 +418,6 @@ def test_ext_add_multi(self):
'--ext-add-pathlist-flex=seven::eight',
])
topt = TestOption1(go_args=args, envvar_prefix='TEST')
#self.assertEqual(topt.options.ext_add_pathlist_flex, ['seven', 'six', 'four', 'p2', 'p3', 'five', 'eight', 'last'])
self.assertEqual(topt.options.ext_add_pathlist_flex, ['seven', 'p2', 'p3', 'eight'])
del os.environ['TEST_EXT_ADD_PATHLIST_FLEX']

Expand Down

0 comments on commit 9edb250

Please sign in to comment.