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

Add unit tests for 'basic_no_decorator.py' and 'compose.py' #111

Merged
merged 15 commits into from
Apr 27, 2020
Merged

Add unit tests for 'basic_no_decorator.py' and 'compose.py' #111

merged 15 commits into from
Apr 27, 2020

Conversation

drewbutlerbb4
Copy link
Member

@drewbutlerbb4 drewbutlerbb4 commented Apr 23, 2020

Resolves #107

Adds functions to help with unit tests for general nested pipelines and pipelines without decorators. Adds unit tests specifically for "basic_no_decorator.py" and "compose.py".

Also addresses some nits from #105

@kubeflow-bot
Copy link

This change is Reviewable

@drewbutlerbb4
Copy link
Member Author

I will update test_kfp_sample.sh once #110 has merged

@ckadner
Copy link
Member

ckadner commented Apr 23, 2020

@drewbutlerbb4 -- #110 has merged, please rebase

@drewbutlerbb4
Copy link
Member Author

test_kfp_samples.sh has been updated. Thanks for the suggestion to restructure the tests, @ckadner, I think this looks a lot cleaner.

@ckadner
Copy link
Member

ckadner commented Apr 23, 2020

Thanks @drewbutlerbb4 -- this looks good, but would you be able to also address the second part of point number 3 mentioned in #107?

  • change the code in test_util.py so that it calls on the new unit test cases and make sure to generate/copy the "golden" YAML and copy them to the specified output path

... to make sure we get the right exit code AND the compiled output YAML -- similar to the parameters of dsl-compile --py <DSL script> --output <YAML file>

see comment :

wrap the compile part into a bash function and inside that function check for IS_SPECIAL:

function compile_dsl {
  if [ -z "${IS_SPECIAL}" ]; then
    dsl-compile-tekton --py "$1" --output "$2"
  else
    python3 -m test_util $1 ${CONFIG_FILE} # need to produce YAML file output
  fi
} 

# ...

    if compile_dsl "${f}" "${TEKTON_COMPILED_YAML_DIR}/${f##*/}.yaml" >> "${COMPILER_OUTPUTS_FILE}" 2>&1 ;
    then
      echo "SUCCESS: ${f##*/}" | tee -a "${COMPILER_OUTPUTS_FILE}"
    else
      echo "FAILURE: ${f##*/}" | tee -a "${COMPILER_OUTPUTS_FILE}"
    fi

If not in this PR, maybe in a follow up? I need that change to restore how the test_kfp_samples.sh script works, to capture the compiler console output as well as exit code and the produced YAML.

@drewbutlerbb4
Copy link
Member Author

@ckadner The least intrusive way of doing this, that I can think of, is to add an optional parameter save_path to TestTektonCompiler method's _test_nested_workflow and _test_workflow_without_decorator. Then call these methods from two new TestTektonCompiler method test_compose_with_save and test_no_decorator_with_save that test_util will call. Is this an acceptable structure or did you have something else in mind?

@drewbutlerbb4
Copy link
Member Author

drewbutlerbb4 commented Apr 23, 2020

On second thought we could add an optional parameter save_path to test_basic_no_decorator and test_compose rather than creating two entirely new methods

@ckadner
Copy link
Member

ckadner commented Apr 23, 2020

On second thought we could add an optional parameter save_path to test_basic_no_decorator and test_compose rather than creating two entirely new methods

Actually, you could just use the "golden" YAML if the test succeeds and store it in the specified path. No need to edit the unit test case. If it fails you should exit with exit code 1 anyway (i.e. raise an Error).

@drewbutlerbb4
Copy link
Member Author

What about in the case where the pipeline compiles but doesn't match the "golden"? Wouldn't the unit test fail and we would record a FAILURE rather than a SUCCESS because it compiled?

@ckadner
Copy link
Member

ckadner commented Apr 24, 2020

What about in the case where the pipeline compiles but doesn't match the "golden"? Wouldn't the unit test fail and we would record a FAILURE rather than a SUCCESS because it compiled?

If the pipeline compiles but does not match the "golden" YAML, then the unit test should fail. If the change in the output YAML is desired, then the "golden" YAML needs to be regenerated (i.e. by flipping the GENERATE_GOLDEN_YAML switch in compiler_tests.py)

The behavior of test_util.py (before this PR) to print out SUCCESS or FAILURE is what I want to get rid of. Instead the test_util.py Python process should return exit code 0 (normal completion) and produce the "golden" YAML file in the specified location, or, if the unit test failed, just exit with an error (process exit code 1) -- which emulates the behavior of dsl-compile-tekton.

@drewbutlerbb4
Copy link
Member Author

Thanks for the clarification @ckadner, amended based on your comments

Copy link
Member

@ckadner ckadner left a comment

Choose a reason for hiding this comment

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

Thank you @drewbutlerbb4 -- this looks good. Just a few nitpicks and small code refactor request

sdk/python/tests/test_kfp_samples.sh Outdated Show resolved Hide resolved
sdk/python/tests/test_kfp_samples.sh Outdated Show resolved Hide resolved
sdk/python/tests/test_kfp_samples.sh Outdated Show resolved Hide resolved
sdk/python/tests/compiler/compiler_tests.py Outdated Show resolved Hide resolved
sdk/python/tests/compiler/testdata/basic_no_decorator.py Outdated Show resolved Hide resolved
sdk/python/tests/compiler/testdata/compose.py Outdated Show resolved Hide resolved
sdk/python/tests/compiler/testdata/compose.py Show resolved Hide resolved
Copy link
Member

@ckadner ckadner left a comment

Choose a reason for hiding this comment

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

Thanks @drewbutlerbb4 -- this looks good. I only have little nitpicks :-)

sdk/python/tests/compiler/testdata/condition.py Outdated Show resolved Hide resolved
sdk/python/tests/test_util.py Outdated Show resolved Hide resolved
sdk/python/tests/compiler/compiler_tests.py Outdated Show resolved Hide resolved
@drewbutlerbb4
Copy link
Member Author

Thanks for the comments @ckadner, amended.

Copy link
Member

@ckadner ckadner left a comment

Choose a reason for hiding this comment

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

Great. Thanks @drewbutlerbb4

/lgtm

@ckadner
Copy link
Member

ckadner commented Apr 27, 2020

/approve

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ckadner

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 2d06e98 into kubeflow:master Apr 27, 2020
HumairAK referenced this pull request in red-hat-data-services/data-science-pipelines-tekton May 16, 2023
Fix artifact passing for recurring runs.
gmfrasca pushed a commit to gmfrasca/data-science-pipelines-tekton that referenced this pull request Aug 25, 2023
Update issue templates with forms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit tests for 'basic_no_decorator.py' and 'compose.py'
4 participants