Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmt t lint should also try to cover adjust rules #1334

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

idorax
Copy link
Contributor

@idorax idorax commented Jul 11, 2022

Fixes #898. If adjust has some L2 keys, we should pick up those keys when invoking Core.lint_keys().

@idorax idorax force-pushed the dev.huanli.20220711.898.lint branch 4 times, most recently from 0f2ddc9 to f233b2a Compare July 11, 2022 13:53
@idorax idorax marked this pull request as draft July 11, 2022 14:02
@idorax idorax force-pushed the dev.huanli.20220711.898.lint branch 3 times, most recently from 1cbc0ca to 336b382 Compare July 12, 2022 08:03
Copy link
Collaborator

@lukaszachy lukaszachy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work unfortunately because 'when' (and 'because') are not known to the lint:

/tests/run/worktree
pass test script must be defined
pass directory path must be absolute
pass directory path must exist
fail unknown attribute 'when' is used
fail unknown attribute 'when' is used

It would be also good to add test to show that lint does its job and points about invalid attribute in adjust rules.

tmt/base.py Outdated
if prop_adjust is not None:
if isinstance(prop_adjust, dict):
node_keys.extend(prop_adjust.keys())
elif isinstance(prop_adjust, list) or isinstance(prop_adjust, tuple):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second argument can be tuple of allowed types so you can use

elif isinstance(prop_adjust, (list, tuple)):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks!

@idorax
Copy link
Contributor Author

idorax commented Jul 12, 2022

Doesn't work unfortunately because 'when' (and 'because') are not known to the lint:

/tests/run/worktree
pass test script must be defined
pass directory path must be absolute
pass directory path must exist
fail unknown attribute 'when' is used
fail unknown attribute 'when' is used

@lukaszachy, Thanks for your quick review. I'm thinking how to get all keywords supported by 'adjust'. Currently known_keys in Core.lint_keys() doesn't include when, because, ...

(Pdb) ll
289  	    def lint_keys(self, additional_keys):
290  	        """ Return list of invalid keys used, empty when all good """
291  	        known_keys = additional_keys + self._keys
292  	        node_keys = list(self.node.get().keys())
293  	        prop_adjust = self.node.get('adjust')
294  	        if prop_adjust is not None:
295 B->	            if isinstance(prop_adjust, dict):
296  	                node_keys.extend(prop_adjust.keys())
......
302  	        return [key for key in node_keys if key not in known_keys]
(Pdb) p additional_keys
['extra-nitrate', 'extra-hardware', 'extra-pepa', 'extra-summary', 'extra-task', 'relevancy', 'coverage', 'adjust']
(Pdb) up
> /home/huanli/.virtualenvs/tmt/lib/python3.10/site-packages/tmt/base.py(572)lint()
-> invalid_keys = self.lint_keys(
(Pdb) l
.......
572  ->	        invalid_keys = self.lint_keys(
573  	            EXTRA_TEST_KEYS + OBSOLETED_TEST_KEYS + ['adjust'])
574  	        if invalid_keys:
......
(Pdb) p EXTRA_TEST_KEYS + OBSOLETED_TEST_KEYS + ['adjust']
['extra-nitrate', 'extra-hardware', 'extra-pepa', 'extra-summary', 'extra-task', 'relevancy', 'coverage', 'adjust']

Any suggestion?

It would be also good to add test to show that lint does its job and points about invalid attribute in adjust rules.

OK, will have a try.

@idorax idorax force-pushed the dev.huanli.20220711.898.lint branch from 336b382 to 149ddbc Compare July 12, 2022 10:22
@lukaszachy
Copy link
Collaborator

@idorax Hm, it gets more complicated. I think check needs to be done in two steps as "adjust" and "when+because" are mutually exclusive. So lint :

  1. test keys + adjust
  2. test keys + when + because

Maybe time to add constants with ['adjust'] and another with ['when', 'because']. I don't think we want them hardcoded but naming such constant will be pain (adjust key itself and keys used by adjust).

@idorax idorax force-pushed the dev.huanli.20220711.898.lint branch from 149ddbc to 0544ee7 Compare July 12, 2022 12:10
@psss
Copy link
Collaborator

psss commented Nov 21, 2023

Any plans with this one, @idorax?

@idorax
Copy link
Contributor Author

idorax commented Nov 28, 2023

Any plans with this one, @idorax?

Currently I don't have bandwidth to work on this issue, let me work on it in 1.32, thanks!

@idorax idorax force-pushed the dev.huanli.20220711.898.lint branch 2 times, most recently from c5020ec to 2653fb5 Compare February 27, 2024 12:30
@lukaszachy lukaszachy self-requested a review February 28, 2024 14:43
tmt/base.py Outdated Show resolved Hide resolved
@lukaszachy
Copy link
Collaborator

Some test to play with:

test: echo
require:
- something

/valid:
  adjust+:
    - when: distro == fedora
      because: showcase
      enabled: true
      environment+:
        FOO: bar
      require-:
        - something
      recommend+<:
        - anything
        
/wrong:
    adjust:
        - qhen: distro == fedora
          env:
            MAGIC: value
          require<+:
          - foo

There should be no "fail" for /valid.
For /wrong is should report wrong key 'qhen', 'env' and 'require<+' (there is no such operation).

@idorax idorax force-pushed the dev.huanli.20220711.898.lint branch from 2653fb5 to 3bcda1f Compare February 29, 2024 01:41
@idorax
Copy link
Contributor Author

idorax commented Feb 29, 2024

Some test to play with:

test: echo
require:
- something

/valid:
  adjust+:
    - when: distro == fedora
      because: showcase
      enabled: true
      environment+:
        FOO: bar
      require-:
        - something
      recommend+<:
        - anything
        
/wrong:
    adjust:
        - qhen: distro == fedora
          env:
            MAGIC: value
          require<+:
          - foo

There should be no "fail" for /valid. For /wrong is should report wrong key 'qhen', 'env' and 'require<+' (there is no such operation).

Thanks, @lukaszachy! Will have a try :-)

@idorax idorax force-pushed the dev.huanli.20220711.898.lint branch from 3bcda1f to 8de53fc Compare March 4, 2024 07:19
@idorax idorax force-pushed the dev.huanli.20220711.898.lint branch from 8de53fc to 7f9ec8c Compare March 8, 2024 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tmt t lint should try to cover adjust rules as well
3 participants