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

Refactor Jupyter magic unit tests #3599

Merged
merged 9 commits into from
Feb 7, 2024

Conversation

noklam
Copy link
Contributor

@noklam noklam commented Feb 5, 2024

Description

Close #3585

Development notes

It seems like a lot of changes but the main change is I use "real" dummy function instead of string, as a result a lot of mocking and function literals are not needed anymore.

  1. Move all those dummy function and dummy function literal (the text of the function) to a separate file. In fact I removed the literal because I can actually use the inspect the module to get it
  2. To use inspect, I need to import it as a module, so the package need to exist, I use logging as the dummy library to replace all package1, package2 etc. We can also mock this but in my experience mocking import will mess up with pytest. This give me the benefit that I don't need to have a lot of """xxxxxx""", instead I just import the real module and retrieve the information from inspect.
  3. Remove all unnecessary mocking because the module is now importable.

Bonus: _prepare_function_body is now basically identical to inspect.getsourcefiles, so there isn't much to test. We can remove the tests if we want, otherwise it can stay in case we change the implementation in the future.

Developer Certificate of Origin

We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a Signed-off-by line in the commit message. See our wiki for guidance.

If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.

Checklist

  • Read the contributing guidelines
  • Signed off each commit with a Developer Certificate of Origin (DCO)
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added a description of this change in the RELEASE.md file
  • Added tests to cover my changes
  • Checked if this change will affect Kedro-Viz, and if so, communicated that with the Viz team

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
…kedro-org/kedro into noklam/refactor-jupyter-magic-unit-3585

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
@noklam noklam self-assigned this Feb 6, 2024
@noklam noklam marked this pull request as ready for review February 6, 2024 14:47
@noklam noklam requested a review from merelcht as a code owner February 6, 2024 14:47
Copy link
Contributor

@AhdraMeraliQB AhdraMeraliQB left a comment

Choose a reason for hiding this comment

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

This is so much easier to follow! 🌟

Copy link
Contributor

@SajidAlamQB SajidAlamQB left a comment

Choose a reason for hiding this comment

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

This is much cleaner and easier to read, awesome work @noklam! 👍

Comment on lines +301 to +304
node_imports = """import logging # noqa
from logging import config # noqa
import logging as dummy_logging # noqa
import logging.config # noqa Dummy import"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we using logging now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SajidAlamQB I have updated this in the PR and it is included in the PR description. In short, this python module need to be importable. The original code use package1,package2 which are not real package, as a result we need to do many mocking.

I choose logging for 2 reasons, 1. it's in standard libraries so no extra dependencies (can be any other standard libraries), 2. It has sub-module so I can test for different kind of import statements. You may swap logging with os and it will do the same job.

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
@noklam noklam enabled auto-merge (squash) February 7, 2024 14:44
@noklam noklam merged commit 670eb09 into main Feb 7, 2024
28 checks passed
@noklam noklam deleted the noklam/refactor-jupyter-magic-unit-3585 branch February 7, 2024 18:31
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.

Refactor jupyter magic unit tests with conftest
3 participants