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

Switching from using diff cover executable to diff cover import #257

Conversation

kelper-hub
Copy link
Contributor

@kelper-hub kelper-hub commented Jan 7, 2025

PR Type

Enhancement, Tests


Description

  • Replaced diff-cover command execution with direct module import.

  • Enhanced error handling for diff-cover integration.

  • Updated tests to validate diff-cover module usage.

  • Added diff-cover dependency and templates to CI and build process.


Changes walkthrough 📝

Relevant files
Enhancement
UnitTestValidator.py
Refactor `diff-cover` integration to use module import     

cover_agent/UnitTestValidator.py

  • Replaced diff-cover command execution with module import.
  • Added error handling for diff-cover execution.
  • Updated logging to reflect new integration.
  • Adjusted method documentation for clarity.
  • +29/-15 
    Tests
    test_UnitTestValidator.py
    Add tests for `diff-cover` module integration                       

    tests/test_UnitTestValidator.py

  • Updated tests to mock diff-cover module usage.
  • Added test for successful diff-cover execution.
  • Added test for handling diff-cover execution failure.
  • Simplified assertion for coverage increase validation.
  • +29/-5   
    Configuration changes
    ci_pipeline.yml
    Update CI pipeline to include `diff-cover`                             

    .github/workflows/ci_pipeline.yml

  • Added diff-cover to pip install dependencies.
  • Ensured CI pipeline supports diff-cover integration.
  • +1/-1     
    Makefile
    Include `diff-cover` templates in build process                   

    Makefile

  • Added diff-cover templates to build process.
  • Ensured diff-cover templates are included in the installer.
  • +3/-0     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    qodo-merge-pro bot commented Jan 7, 2025

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The error handling for diff-cover execution only logs the error but doesn't propagate it. Consider whether errors should fail the coverage report generation.

    try:
        diff_cover_main(diff_cover_args)
    except Exception as e:
        self.logger.error(f"Error running diff-cover: {e}")

    Copy link
    Contributor

    qodo-merge-pro bot commented Jan 7, 2025

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add proper exit code validation to ensure the command executed successfully

    Add a return value check for diff_cover_main() to ensure the report was generated
    successfully, as the function might return a non-zero exit code without raising an
    exception.

    cover_agent/UnitTestValidator.py [717-720]

     try:
    -    diff_cover_main(diff_cover_args)
    +    result = diff_cover_main(diff_cover_args)
    +    if result != 0:
    +        self.logger.error(f"diff-cover failed with exit code: {result}")
    +        raise Exception(f"diff-cover failed with exit code: {result}")
     except Exception as e:
         self.logger.error(f"Error running diff-cover: {e}")
    +    raise
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion adds crucial error handling by checking the return value of diff_cover_main, which could fail silently. This prevents potential issues where coverage reports might be incomplete or invalid.

    8
    General
    Add input file validation to prevent runtime errors with missing files

    Verify that the coverage report files exist before running diff-cover to prevent
    cryptic errors and provide better error messages.

    cover_agent/UnitTestValidator.py [708-714]

    +if not os.path.exists(self.code_coverage_report_path):
    +    raise FileNotFoundError(f"Coverage report not found: {self.code_coverage_report_path}")
     diff_cover_args = [
         "diff-cover",
         "--json-report",
         self.diff_cover_report_path,
         "--compare-branch={}".format(self.comparison_branch),
         self.code_coverage_report_path
     ]
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding file existence checks before running diff-cover provides better error handling and user feedback, preventing cryptic runtime errors that could be confusing to debug.

    7

    @kelper-hub
    Copy link
    Contributor Author

    Old PR: #237

    @kelper-hub kelper-hub force-pushed the user/kepler-hub/using-diff-coverage-import branch from 39bee5b to 798ec11 Compare January 7, 2025 04:53
    @kelper-hub kelper-hub force-pushed the user/kepler-hub/using-diff-coverage-import branch from a9b0f81 to a2dbb58 Compare January 7, 2025 04:56
    @EmbeddedDevops1 EmbeddedDevops1 merged commit 48f933f into qodo-ai:main Jan 7, 2025
    7 checks passed
    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