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

Raise error if malformed test metadata is given #1905

Merged
merged 1 commit into from
Jun 20, 2023

Conversation

idorax
Copy link
Contributor

@idorax idorax commented Mar 9, 2023

Fix: #1881

@idorax
Copy link
Contributor Author

idorax commented Mar 9, 2023

With the patch, the test result looks like:

$ cat main.fmf 
summary: Concise summary describing what the test does
test: false 
framework: beakerlib

$ tmt run -avvv provision -h local
/var/tmp/tmt/run-001
Found 1 plan.

/plans/foo
summary: Basic smoke test
    discover
        how: fmf
        order: 50
        directory: /home/huanli/dev/1881/foo
                warn: /tests/foo:test - False is not of type 'string'
    finish
        prune: Prune plan workdir '/var/tmp/tmt/run-001/plans/foo'.
        summary: 0 tasks completed
Oops, False is not of type 'string'.

Hi @lukaszachy and @happz, please help to review, thanks!

tmt/base.py Outdated Show resolved Hide resolved
@idorax idorax marked this pull request as draft March 13, 2023 07:39
@idorax idorax force-pushed the dev-huanli-1881-20230309-test-metadata branch from bd7c961 to d7088d2 Compare June 6, 2023 13:24
@idorax idorax marked this pull request as ready for review June 6, 2023 13:25
@idorax idorax requested a review from thrix as a code owner June 6, 2023 13:25
@idorax
Copy link
Contributor Author

idorax commented Jun 6, 2023

Hi @happz, with your PR #1869,

I don't know how to check raw_value is a str in a lambda function, so I added the check to ShellScript.__init__(). Please help to review and correct me if it's incorrect, thanks!

@idorax idorax force-pushed the dev-huanli-1881-20230309-test-metadata branch from d7088d2 to 254bb5e Compare June 6, 2023 13:32
@happz
Copy link
Collaborator

happz commented Jun 6, 2023

Hi @happz, with your PR #1869,

I don't know how to check raw_value is a str in a lambda function, so I added the check to ShellScript.__init__(). Please help to review and correct me if it's incorrect, thanks!

lambdas are a bit too clumsy in Python, once there are more than just a few actions to take. How about adding tmt.utils.normalize_shell_script()? There's already normalize_shell_script_list(), we can have one for a single script test allow, and make it nice and readable.

@idorax
Copy link
Contributor Author

idorax commented Jun 6, 2023

lambdas are a bit too clumsy in Python, once there are more than just a few actions to take. How about adding tmt.utils.normalize_shell_script()? There's already normalize_shell_script_list(), we can have one for a single script test allow, and make it nice and readable.

Hi @happz, function tmt.utils.normalize_shell_script() is added. Now the test result looks like:

$ cat main.fmf 
summary: Concise summary describing what the test does
test: false 
framework: beakerlib
$ tmt run -avvv provision -h local
/var/tmp/tmt/run-056
Found 1 plan.

/plans/foo
summary: Basic smoke test
    discover
        how: fmf
        order: 50
        directory: /home/huanli/dev/1881/foo
                warn: /tests/foo:test - False is not of type 'string'
    finish
    
    Prune '/plans/foo' plan workdir '/var/tmp/tmt/run-056/plans/foo'.
        summary: 0 tasks completed

Field '/tests/foo:test' must be a string, 'bool' found.

Please help to review again, thanks!

tmt/base.py Outdated Show resolved Hide resolved
tmt/utils.py Outdated Show resolved Hide resolved
@idorax idorax force-pushed the dev-huanli-1881-20230309-test-metadata branch from 3cb51c7 to 3bba56c Compare June 6, 2023 15:06
@happz happz added this to the 1.25 milestone Jun 6, 2023
@idorax idorax force-pushed the dev-huanli-1881-20230309-test-metadata branch 3 times, most recently from 95a2837 to 5e047e4 Compare June 7, 2023 12:54
@idorax
Copy link
Contributor Author

idorax commented Jun 7, 2023

Hi @happz and @lukaszachy , a simple test is added, please help to review, thanks!

@idorax idorax force-pushed the dev-huanli-1881-20230309-test-metadata branch from 5e047e4 to 7a16e89 Compare June 13, 2023 01:34
tmt/utils.py Show resolved Hide resolved
Copy link
Collaborator

@psss psss left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

If a malformed test metadata is given by user, e.g.
    test: false
an error should be raised because the type of the test metadata is not
string. Then user can fix it accordingly.

Signed-off-by: Vector Li <[email protected]>
@psss psss force-pushed the dev-huanli-1881-20230309-test-metadata branch from 2196fdf to ffdd6a1 Compare June 20, 2023 13:07
@psss psss self-assigned this Jun 20, 2023
@psss psss added the code | utils Various utility functions and classes used across the code label Jun 20, 2023
@psss psss added the code | base Base classes implementation in base.py label Jun 20, 2023
@psss
Copy link
Collaborator

psss commented Jun 20, 2023

The failing test is irrelevant, known issue #2063.

@psss psss merged commit ffdd6a1 into main Jun 20, 2023
@psss psss deleted the dev-huanli-1881-20230309-test-metadata branch June 20, 2023 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code | base Base classes implementation in base.py code | utils Various utility functions and classes used across the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Traceback for malformed test metadata
3 participants