Skip to content

Commit

Permalink
core: fix config file list handling
Browse files Browse the repository at this point in the history
if a config file is used and a e.g. statement is
used via CLI, the config parts need to be turned into
a list

Closes #681

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Jan 10, 2025
1 parent 51a225a commit af4d763
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions oelint_adv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __call__(self, parser, namespace, values, option_string=None) -> None:
if not isinstance(values, str):
return # pragma: no cover
items = getattr(namespace, self.dest) or []
if not isinstance(items, list):
items = [x.strip() for x in items.split() if x.strip()]
items.extend(RegexRpl.split(r'\s+|\t+|\n+', values.strip('"').strip("'")))
setattr(namespace, self.dest, items)

Expand Down
79 changes: 79 additions & 0 deletions tests/test_configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,82 @@ def test_option_deserialization(self):
options = {'a': 'True', 'b': True, 'c': 'False', 'd': False, 'e': 'other value'}
deserialized = deserialize_boolean_options(options)
assert deserialized == {'a': True, 'b': True, 'c': False, 'd': False, 'e': 'other value'}

@pytest.mark.parametrize('input_',
[
{
'oelint adv-test.bb':
'''
VAR:append:prepend = "1"
''',
},
],
)
def test_config_file_suppress(self, input_):
_cstfile = self._create_tempfile(
'.oelint.cfg',
'''
[oelint]
suppress=
oelint.vars.doublemodify
oelint.var.suggestedvar.BUGTRACKER
''')
os.environ['OELINT_CONFIG'] = _cstfile
_args = self._create_args(input_)
self.check_for_id(_args, 'oelint.vars.doublemodify', 0)
self.check_for_id(_args, 'oelint.var.suggestedvar.BUGTRACKER', 0)
self.check_for_id(_args, 'oelint.var.mandatoryvar.LICENSE', 1)

@pytest.mark.parametrize('input_',
[
{
'oelint adv-test.bb':
'''
VAR:append:prepend = "1"
''',
},
],
)
def test_config_file_suppress_merge_with_cli(self, input_):
_cstfile = self._create_tempfile(
'.oelint.cfg',
'''
[oelint]
suppress=
oelint.vars.doublemodify
oelint.var.suggestedvar.BUGTRACKER
''')
os.environ['OELINT_CONFIG'] = _cstfile
_args = self._create_args(input_, ['--suppress', 'oelint.var.mandatoryvar.LICENSE'])
self.check_for_id(_args, 'oelint.vars.doublemodify', 0)
self.check_for_id(_args, 'oelint.var.suggestedvar.BUGTRACKER', 0)
self.check_for_id(_args, 'oelint.var.mandatoryvar.LICENSE', 0)
self.check_for_id(_args, 'oelint.var.mandatoryvar.HOMEPAGE', 1)

@pytest.mark.parametrize('input_',
[
{
'oelint adv-test.bb':
'''
VAR:append:prepend = "1"
''',
},
],
)
def test_config_file_suppress_merge_with_cli_multiple(self, input_):
_cstfile = self._create_tempfile(
'.oelint.cfg',
'''
[oelint]
suppress=
oelint.vars.doublemodify
oelint.var.suggestedvar.BUGTRACKER
''')
os.environ['OELINT_CONFIG'] = _cstfile
_args = self._create_args(input_,
['--suppress', 'oelint.var.mandatoryvar.LICENSE',
'--suppress', 'oelint.var.mandatoryvar.HOMEPAGE'])
self.check_for_id(_args, 'oelint.vars.doublemodify', 0)
self.check_for_id(_args, 'oelint.var.suggestedvar.BUGTRACKER', 0)
self.check_for_id(_args, 'oelint.var.mandatoryvar.LICENSE', 0)
self.check_for_id(_args, 'oelint.var.mandatoryvar.HOMEPAGE', 0)

0 comments on commit af4d763

Please sign in to comment.