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: stress ratio calculations #1418

Merged
merged 3 commits into from
Oct 13, 2024
Merged

Conversation

weibullguy
Copy link
Collaborator

@weibullguy weibullguy commented Oct 13, 2024

Does this PR introduce a breaking change?

  • Yes
  • No

Purpose of this pull request

This pull request refactors the calculate_stress_ratio function to improve error handling and input validation. Specifically, it introduces validation to ensure that neither the operating nor the rated stress values are negative. Additionally, a new set of unit tests has been added to cover edge cases, including handling of zero and negative input values, as well as testing invalid data types.

Benefits of the pull request

  • Ensures that stress values are validated correctly to avoid incorrect stress ratio calculations when negative values are passed.
  • Increases code robustness by raising appropriate exceptions (ValueError for negative inputs, ZeroDivisionError for zero-rated stress).
  • Enhances test coverage by introducing tests for edge cases such as negative inputs, zero operating stress, and mixed valid/invalid inputs.
  • Improves code readability and maintainability by adhering to better validation practices.

Any particular area(s) reviewers should focus on

  • Review the input validation logic in calculate_stress_ratio to ensure that it handles negative and zero inputs as expected.
  • Review the added test cases to confirm that they cover all relevant edge cases.
  • Ensure that no valid inputs are unintentionally rejected with the updated validation logic.

Any other pertinent information.

Pull Request Checklist

  • Code Style

    • Code is following code style guidelines.
  • Static Checks

    • Failing static checks are only applicable to code outside the scope of
      this PR.
  • Tests

    • At least one test for all newly created functions/methods?
  • Chores

    • Issue(s) have been raised for problem areas outside the scope of
      this PR. These problem areas have been decorated with an ISSUE: # comment.

Summary by Sourcery

Refactor the calculate_stress_ratio function to enhance error handling and input validation, ensuring robustness against negative and zero values. Introduce comprehensive unit tests to cover edge cases and validate the new logic.

Enhancements:

  • Refactor the calculate_stress_ratio function to improve error handling and input validation, ensuring non-negative stress values and proper exception handling for invalid inputs.

Tests:

  • Add new unit tests to cover edge cases for the calculate_stress_ratio function, including handling of zero and negative input values, and testing invalid data types.

Chores:

  • Update copyright information in the test and source files.

Copy link
Contributor

sourcery-ai bot commented Oct 13, 2024

Reviewer's Guide by Sourcery

This pull request refactors the stress ratio calculations to improve error handling and input validation. The changes focus on enhancing the robustness of the calculate_stress_ratio function by introducing proper input validation, improving error handling, and expanding the test coverage to include edge cases.

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

File-Level Changes

Change Details Files
Refactored calculate_stress_ratio function for improved input validation and error handling
  • Added type checking for input parameters
  • Implemented validation for non-negative stress values
  • Improved error handling for zero-rated stress
  • Raised ValueError for negative stress inputs
src/ramstk/analyses/stress.py
Extended unit tests for stress ratio calculations
  • Added test for negative operating stress
  • Added test for negative rated stress
  • Added test for zero operating stress
  • Added test for both operating and rated stresses being zero
tests/analyses/test_stress.py
Updated copyright information and file headers
  • Changed copyright year from 2019 to 'since 2007'
  • Corrected file name in header comment
src/ramstk/analyses/stress.py
tests/analyses/test_stress.py
Improved pull request template
  • Reworded section headers for clarity
  • Adjusted formatting for consistency
.github/PULL_REQUEST_TEMPLATE.md

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

@github-actions github-actions bot added the type: refactor Issue or PR dealing with refactoring of RAMSTK code. label Oct 13, 2024
@weibullguy weibullguy added priority: low Issue or PR is low priority. status: inprogress Issue or PR is open, milestoned, and assigned. labels Oct 13, 2024
Copy link
Contributor

@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 @weibullguy - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

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.

tests/analyses/test_stress.py Show resolved Hide resolved
tests/analyses/test_stress.py Show resolved Hide resolved
tests/analyses/test_stress.py Show resolved Hide resolved
.github/PULL_REQUEST_TEMPLATE.md Outdated Show resolved Hide resolved
@weibullguy weibullguy merged commit 7226951 into master Oct 13, 2024
19 checks passed
@weibullguy weibullguy deleted the refactor/stress_ratio branch October 13, 2024 03:25
@trafico-bot trafico-bot bot added the endgame: merged Pull Request has been merged successfully label Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
endgame: merged Pull Request has been merged successfully priority: low Issue or PR is low priority. status: inprogress Issue or PR is open, milestoned, and assigned. type: refactor Issue or PR dealing with refactoring of RAMSTK code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant