poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Add unit tests for helpers

Open j7an opened this issue 10 months ago • 1 comments

Add unit tests for get_package, get_dependency, copy_path, MockDulwichRepo. Organize isolated_environment tests into test class

Pull Request Check List

Partially resolves: #9161

  • [x] Added tests for changed code.
  • [ ] Updated documentation for changed code.

Summary by Sourcery

Add comprehensive unit tests for helper functions in the test suite

New Features:

  • Created detailed test coverage for helper utility functions in the test suite

Tests:

  • Introduced new test classes for get_package, get_dependency, copy_path, and MockDulwichRepo helper functions
  • Reorganized isolated_environment tests into a dedicated test class
  • Added parameterized tests to cover various input scenarios and edge cases for helper functions

j7an avatar Mar 30 '25 06:03 j7an

Reviewer's Guide by Sourcery

This pull request adds comprehensive unit tests for several helper functions, including get_package, get_dependency, copy_path, and MockDulwichRepo. It also organizes the isolated environment tests into a dedicated test class. The tests cover various scenarios and input types to ensure the correct behavior of these helper functions.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Added unit tests for the get_package helper function, covering different scenarios such as string and Version object inputs, and yanked package handling.
  • Created a test class TestGetPackage to encapsulate tests for get_package.
  • Added a fixture base_package for common setup.
  • Added test test_get_package_with_string_name to verify package name.
  • Added test test_get_package_version_handling to test version handling with string and Version object inputs.
  • Added test test_get_package_yanked_handling to test yanked package handling.
tests/test_helpers.py
Added unit tests for the get_dependency helper function, covering name, constraint, optional, and prerelease scenarios.
  • Created a test class TestGetDependency to encapsulate tests for get_dependency.
  • Added a fixture base_dependency for common setup.
  • Added test test_get_dependency_name to verify dependency name.
  • Added test test_get_dependency_default_constraint_value to verify default constraint value.
  • Added test test_get_dependency_defaults_to_false_optional to verify default optional value.
  • Added test test_get_dependency_default_to_false_allow_prereleases to verify default allow prereleases value.
  • Added test test_get_dependency_constraint_handling to test constraint handling with different input types.
  • Added test test_get_dependency_with_complex_dict_constraint to test constraint handling with complex dictionary input.
  • Added test test_get_dependency_with_groups to test groups handling.
  • Added test test_get_dependency_boolean_params to test boolean parameters.
tests/test_helpers.py
Added unit tests for the copy_path helper function, covering file and directory copy scenarios to new and existing destinations.
  • Created a test class TestCopyPath to encapsulate tests for copy_path.
  • Added a fixture setup_files to create source and destination files and directories.
  • Added test test_copy_file_to_new_destination to test copying a file to a new destination.
  • Added test test_copy_file_to_existing_file to test copying a file to an existing file.
  • Added test test_copy_file_to_existing_directory to test copying a file to an existing directory.
  • Added test test_copy_directory_to_new_destination to test copying a directory to a new destination.
  • Added test test_copy_directory_to_existing_directory to test copying a directory to an existing directory.
  • Added test test_copy_directory_to_existing_file to test copying a directory to an existing file.
tests/test_helpers.py
Added unit tests for the MockDulwichRepo helper class, covering initialization with different path types and head method behavior.
  • Created a test class TestMockDulwichRepo to encapsulate tests for MockDulwichRepo.
  • Added a fixture repo_path to create a temporary repository path.
  • Added test test_init_with_path_object to test initialization with a Path object.
  • Added test test_init_with_string_path to test initialization with a string path.
  • Added test test_head_returns_default_revision_encoded to test the head method returns the default revision encoded.
  • Added test test_init_ignores_extra_kwargs to test that extra keyword arguments are ignored during initialization.
tests/test_helpers.py
Organized the isolated environment tests into a test class.
  • Created a test class TestIsolatedEnvironment to encapsulate tests for isolated_environment.
  • Moved the test_isolated_environment_restores_original_environ test into the new class.
  • Moved the test_isolated_environment_clears_environ test into the new class.
  • Moved the test_isolated_environment_updates_environ test into the new class.
tests/test_helpers.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Mar 30 '25 06:03 sourcery-ai[bot]