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

Add xdoctest #141

Merged
merged 2 commits into from
Nov 19, 2024
Merged

Add xdoctest #141

merged 2 commits into from
Nov 19, 2024

Conversation

Erotemic
Copy link
Contributor

@Erotemic Erotemic commented Sep 15, 2024

This PR tweaks some of the CI to include xdoctest as a pytest plugin and run doctests on the repo. I've also added code coverage and one simple doctest as an example. I cleaned up one unused import in setup.py

Summary by CodeRabbit

  • New Features

    • Added a configuration file to enhance project build, testing, and coverage capabilities.
    • Introduced a docstring example for the CyclicAudioBuffer class to improve documentation.
  • Bug Fixes

    • Improved logging messages for better clarity and error handling in various methods.
  • Chores

    • Updated testing requirements with new dependencies for enhanced testing capabilities.
    • Minor formatting adjustments in requirements management.

Copy link
Contributor

coderabbitai bot commented Sep 15, 2024

Walkthrough

This pull request introduces several changes across multiple files, enhancing unit testing capabilities, improving logging practices, modifying error handling, and updating project configuration. Key updates include the introduction of a pyproject.toml file for project management, refinements in logging messages for better clarity, and the addition of new dependencies to support testing. Overall, the changes aim to improve code maintainability and testing processes without altering core functionalities.

Changes

Files Change Summary
.github/workflows/unit_tests.yml Enhanced pytest command with coverage options, HTML report generation, and test duration measurement.
ovos_dinkum_listener/service.py Improved logging in _handle_listen and reload_configuration methods; refined exception handling and simplified log messages.
ovos_dinkum_listener/transformers.py Modified error handling in load_plugins method by removing the exception variable from the except clause, impacting clarity of error reporting.
ovos_dinkum_listener/voice_loop/hotwords.py Added a docstring example for the CyclicAudioBuffer class to improve documentation.
pyproject.toml Introduced a configuration file for build system and tools, specifying settings for type checking, testing, coverage reporting, and documentation testing.
requirements/tests.txt Added new dependencies xdoctest~=1.1.5, pytest-cov>=3.0.0, and coverage>=7.2.7; duplicated line for ovos-vad-plugin-webrtcvad.
setup.py Removed import statement for Path from pathlib, indicating a change in file path handling logic.

Possibly related PRs

  • chore:semver_versioning #132: The changes in requirements/tests.txt related to the addition of pytest-cov>=3.0.0 and coverage>=7.2.7 enhance testing capabilities, which aligns with the main PR's focus on improving unit test execution and coverage reporting.
  • refactor:extras_requirements #136: The modifications in requirements/extras.txt that expand the list of dependencies for audio processing may indirectly relate to the overall testing and functionality improvements in the main PR, although they do not directly affect the testing framework itself.

Suggested labels

ignore-for-release

Poem

🐇 In the code where bunnies hop,
Changes made, we’ll never stop!
Tests now run with flair and grace,
Logging clear in every place.
With plugins new, our tools align,
Hooray for code, it’s simply fine! 🥕


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between de27d33 and d9eb3e6.

Files selected for processing (1)
  • requirements/tests.txt (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • requirements/tests.txt

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 07b6a22 and de27d33.

Files selected for processing (7)
  • .github/workflows/unit_tests.yml (1 hunks)
  • ovos_dinkum_listener/service.py (6 hunks)
  • ovos_dinkum_listener/transformers.py (1 hunks)
  • ovos_dinkum_listener/voice_loop/hotwords.py (1 hunks)
  • pyproject.toml (1 hunks)
  • requirements/tests.txt (1 hunks)
  • setup.py (0 hunks)
Files not reviewed due to no reviewable changes (1)
  • setup.py
Files skipped from review due to trivial changes (3)
  • ovos_dinkum_listener/service.py
  • ovos_dinkum_listener/voice_loop/hotwords.py
  • requirements/tests.txt
Additional comments not posted (7)
pyproject.toml (6)

1-3: LGTM!

The [build-system] section is correctly configured with the appropriate requires and build-backend fields for a Python project using setuptools.


5-6: Approved with a note of caution.

The [tool.mypy] section is correctly configured to ignore missing imports, which can help streamline development by reducing noise from unresolved dependencies.

However, please be cautious when using this configuration as it may also mask potential issues with missing imports. Ensure that all required dependencies are properly installed and imported in the code.


8-11: LGTM!

The [tool.pytest.ini_options] section is correctly configured with appropriate options for testing and test discovery.

  • The addopts field enables running doctests and ignores the setup.py file during test discovery.
  • The norecursedirs field excludes unnecessary directories from test discovery.
  • The filterwarnings field sets the default warning filter.

These configurations enhance the testing process by focusing on relevant files and enabling doctests.


13-15: LGTM!

The [tool.coverage.run] section is correctly configured to collect meaningful coverage data for the ovos_dinkum_listener package.

  • The branch field is set to true, ensuring that branch coverage is collected.
  • The source field specifies the ovos_dinkum_listener package as the source of coverage data, focusing the coverage analysis on the relevant code.

These configurations contribute to effective coverage analysis and reporting.


17-35: LGTM!

The [tool.coverage.report] section is correctly configured to exclude irrelevant or intentionally uncovered lines from coverage reports.

  • The exclude_lines field specifies a comprehensive list of regular expressions matching lines to exclude, such as those marked with specific comments, certain control flow statements, and other patterns.
  • The omit field excludes the setup.py file from coverage reports.

These configurations ensure that the coverage metrics reflect meaningful code and provide a more accurate representation of the project's test coverage.


37-38: LGTM!

The [tool.xdoctest] section is present with an empty options field, indicating that the project is ready for documentation testing using xdoctest.

Although no additional options are specified, the presence of this section suggests that xdoctest is properly integrated into the project's testing workflow.

.github/workflows/unit_tests.yml (1)

57-57: Excellent improvements to the testing process!

The updated pytest command introduces several beneficial changes:

  • Specifying the coverage configuration file ensures consistent coverage settings.
  • Generating an HTML coverage report provides a visual representation of test coverage, making it easier to identify areas that may require additional testing.
  • Providing terminal output for coverage gives immediate feedback during test runs.
  • Measuring test durations helps identify slow tests that may need optimization, contributing to faster CI/CD pipelines.
  • Setting the coverage target to the ovos_dinkum_listener module ensures that the coverage metrics are focused on the relevant code.

These enhancements will greatly improve the quality and maintainability of the codebase by providing more comprehensive and informative test results.

ovos_dinkum_listener/transformers.py Outdated Show resolved Hide resolved
@@ -54,4 +54,4 @@ jobs:
pip install -r requirements/tests.txt
- name: Run unittests
run: |
pytest test/unittests
pytest --cov-config pyproject.toml --cov-report html --cov-report term --durations 5 --cov=ovos_dinkum_listener

Choose a reason for hiding this comment

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

Consider a pytest.ini file, as this could start to get unwieldy

Choose a reason for hiding this comment

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

Or add it to pyproject.toml, which I just noticed you added

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are extra options on top of the ones in pyproject.toml. Adding coverage is not free, and often a single run of pytest is enough for a developer, so I wanted to ensure the pyproject-level options enabled all test by default, but I only wanted the extra coverage reporting on the CI.

But this is a design decision, and making CI and the user the same by default is reasonable. Typically what I do is I add a "./run_tests.sh" script to my repo root, which does the tests with coverage, but leave pytest just run the tests and don't bother with coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this is a better example of a more modern run_tests.py that I use:

https://gitlab.kitware.com/computer-vision/kwimage/-/blob/main/run_tests.py?ref_type=heads

@JarbasAl JarbasAl merged commit baa133f into OpenVoiceOS:dev Nov 19, 2024
10 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 19, 2024
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.

3 participants