Skip to content

Enhance tests for FetchNode with mocking #354

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

Merged
merged 1 commit into from
Jun 9, 2024

Conversation

tejhande
Copy link
Contributor

@tejhande tejhande commented Jun 7, 2024

This commit enhances the test suite for the FetchNode class by introducing mocking for the execute method using the unittest.mock module.

Changes:

  • Imported the patch and MagicMock classes from unittest.mock.
  • Decorated each test function with @patch('scrapegraphai.nodes.FetchNode.execute') to mock the execute method.
  • Set the return_value of the mocked execute method to a MagicMock instance.
  • Added assertions to check if the mocked execute method was called with the expected state dictionary.
  • Updated the test functions to use the mocked execute method instead of the actual implementation.

Benefits:

  • Improved test reliability by isolating the FetchNode class from external dependencies.
  • Faster test execution since external resources (e.g., URLs, files) are not required.
  • Better test coverage by testing the execute method's behavior with various input states.
  • Increased maintainability by decoupling tests from the implementation details of the execute method.

The functionality of the FetchNode class remains unchanged, but the tests now use mocking to ensure the correct behavior of the execute method without relying on external resources or dependencies.

This commit enhances the test suite for the FetchNode class by introducing mocking for the execute method using the unittest.mock module.

Changes:
- Imported the patch and MagicMock classes from unittest.mock.
- Decorated each test function with @patch('scrapegraphai.nodes.FetchNode.execute') to mock the execute method.
- Set the return_value of the mocked execute method to a MagicMock instance.
- Added assertions to check if the mocked execute method was called with the expected state dictionary.
- Updated the test functions to use the mocked execute method instead of the actual implementation.

Benefits:
- Improved test reliability by isolating the FetchNode class from external dependencies.
- Faster test execution since external resources (e.g., URLs, files) are not required.
- Better test coverage by testing the execute method's behavior with various input states.
- Increased maintainability by decoupling tests from the implementation details of the execute method.

The functionality of the FetchNode class remains unchanged, but the tests now use mocking to ensure the correct behavior of the execute method without relying on external resources or dependencies.
@VinciGit00
Copy link
Collaborator

hi, we would be glad if you can update also the other nodes test, thank you!

@VinciGit00 VinciGit00 merged commit 14d1011 into ScrapeGraphAI:main Jun 9, 2024
2 checks passed
@tejhande
Copy link
Contributor Author

tejhande commented Jun 9, 2024

Thank you for merging the pull request and for the feedback! I will be glad to update the tests for the other nodes as well.

Copy link

github-actions bot commented Jun 9, 2024

🎉 This PR is included in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

github-actions bot commented Jun 9, 2024

🎉 This PR is included in version 1.6.0-beta.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

2 participants