Skip to content

test: add test coverage for tests/helpers.py#10778

Open
joewanko wants to merge 1 commit intopython-poetry:mainfrom
joewanko:add-helpers-test-coverage
Open

test: add test coverage for tests/helpers.py#10778
joewanko wants to merge 1 commit intopython-poetry:mainfrom
joewanko:add-helpers-test-coverage

Conversation

@joewanko
Copy link
Copy Markdown

@joewanko joewanko commented Mar 22, 2026

Summary

This PR adds comprehensive test coverage for helper functions in tests/helpers.py that were previously untested.

Changes

New tests added for:

  • get_package: Tests package creation with name, version, and various yanked states (bool and string)
  • get_dependency: Tests dependency creation with different constraints, optional flags, groups, and prereleases
  • copy_path: Tests file and directory copying, including overwrite behavior
  • with_working_directory: Tests the context manager for changing working directories with optional copy behavior
  • pbs_installer_supported_arch: Tests architecture detection for supported architectures (arm64, aarch64, amd64, x86_64, i686, x86)

Reorganization

  • Organized existing tests into classes for better structure and maintainability
  • Maintained backward compatibility with existing test assertions

Testing

All 43 tests pass:

poetry run pytest tests/test_helpers.py -v
# 43 passed in 1.78s

Related Issue

Closes #9161


This is my first contribution to Poetry - happy to make any adjustments based on feedback!

Summary by Sourcery

Add comprehensive unit tests for helper utilities and organize existing helper tests into structured test classes.

Tests:

  • Add test coverage for get_package, get_dependency, copy_path, with_working_directory, and pbs_installer_supported_arch helpers.
  • Refactor existing flatten_dict, isolated_environment, and switch_working_directory tests into class-based test suites for better structure.

Adds comprehensive tests for helper functions that were previously untested:
- get_package: tests package creation with various yanked states
- get_dependency: tests dependency creation with constraints, groups, etc.
- copy_path: tests file and directory copying with overwrite behavior
- with_working_directory: tests working directory context manager
- pbs_installer_supported_arch: tests architecture detection

Also reorganizes existing tests into classes for better structure.

Closes python-poetry#9161
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 22, 2026

Reviewer's Guide

Adds comprehensive unit tests for helper utilities in tests/helpers.py, reorganizing existing tests into structured test classes while preserving prior behavior, and increasing coverage for package/dependency helpers, filesystem helpers, environment/working-directory context managers, and architecture support detection.

File-Level Changes

Change Details Files
Add tests for get_package helper covering basic package creation and yanked flag semantics.
  • Introduce TestGetPackage test class with targeted unit tests.
  • Verify name and version handling for created packages.
  • Assert yanked flag behavior for boolean and string inputs.
tests/test_helpers.py
Add tests for get_dependency helper for different constraint, optionality, grouping, and prerelease configurations.
  • Introduce TestGetDependency test class with tests for default wildcard constraint and explicit version constraints.
  • Cover dict-style constraints including extras.
  • Validate optional dependencies, group assignment, and prerelease allowance flags.
tests/test_helpers.py
Add tests for copy_path and with_working_directory filesystem helpers, including copy behavior, overwrites, cleanup, and isolation of source vs copied content.
  • Introduce TestCopyPath to assert copying files and directories and overwriting existing targets.
  • Introduce TestWithWorkingDirectory to validate behavior when changing into a source directory vs a copied target directory.
  • Verify that temporary target directories are cleaned up and source content is not mutated when using copies.
tests/test_helpers.py
Extend tests for flatten_dict, isolated_environment, and switch_working_directory, organizing them into classes and adding additional scenarios.
  • Refactor existing standalone tests into TestFlattenDict, TestIsolatedEnvironment, and TestSwitchWorkingDirectory classes.
  • Add additional flatten_dict cases for deeply nested, empty, and already-flat dictionaries.
  • Preserve and slightly restructure environment and working-directory tests while keeping behavior identical.
tests/test_helpers.py
Add parameterized tests for pbs_installer_supported_arch to cover multiple architectures and case-insensitive handling.
  • Create TestPbsInstallerSupportedArch with parameterized arch/expected pairs.
  • Verify supported architectures across arm64/aarch64/amd64/x86_64/i686/x86 with varying case.
  • Assert unsupported results for non-matching architectures and edge cases such as empty strings.
tests/test_helpers.py

Assessment against linked issues

Issue Objective Addressed Explanation
#9161 Add test coverage for the helper utilities defined in tests/helpers.py (e.g., get_package, get_dependency, copy_path, with_working_directory, pbs_installer_supported_arch, and existing helpers) by extending 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!

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

Add test coverage for tests/helpers.py

1 participant