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

fix: update deprecated imports from ovos-utils #611

Merged
merged 1 commit into from
Nov 21, 2024
Merged

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Nov 21, 2024

Summary by CodeRabbit

  • Bug Fixes

    • Updated import statements for FakeBus and Message across various test files to reflect new module organization.
  • Refactor

    • Enhanced test structure by consistently applying configuration mocking across test classes.
    • Removed unnecessary mocking methods in TestSkillManager to simplify test setup.

These changes improve the reliability and maintainability of the testing framework while ensuring consistent behavior across tests.

Copy link

coderabbitai bot commented Nov 21, 2024

Walkthrough

The changes in this pull request primarily involve modifications to import statements across various test files, specifically transitioning the source of FakeBus and Message from ovos_utils.messagebus to ovos_utils.fakebus. Additionally, several test classes have been updated to include a consistent mocking strategy for configuration loading. Some methods have been removed to simplify the test setup, while the overall structure and functionality of the tests remain intact.

Changes

File Path Change Summary
test/backwards_compat/test_ocp.py Updated import for FakeBus. Modified setUpClass in TestOCPLoad and TestCPS to include mocking.
test/end2end/minicroft.py Updated import for FakeBus. No other changes made.
test/integrationtests/common_query/test_continuous_dialog.py Updated import for Message to FakeMessage. Structure unchanged.
test/integrationtests/common_query/test_skill.py Updated import for FakeBus. No other changes made.
test/integrationtests/test_workshop.py Updated import for Message to FakeMessage. Structure unchanged.
test/unittests/test_skill_manager.py Removed _mock_skill_updater and _mock_skill_settings_downloader methods from TestSkillManager.
test/unittests/xformers.py Updated import for FakeBus. No other changes made.

Possibly related PRs

  • feat/pipeline_plugins_opm #527: The changes in this PR involve modifications to import statements for FakeBus, which is also a focus in the main PR. Both PRs reflect a restructuring of module organization related to the FakeBus class.
  • requirements:latest stable packages #563: This PR includes updates to import statements across multiple files, including changes that may relate to the overall structure and organization of the codebase, similar to the changes made in the main PR regarding import statements in test files.

Suggested labels

refactor, packaging

Suggested reviewers

  • goldyfruit
  • j1nx
  • builderjer

Poem

In the code where rabbits hop,
Imports shift and never stop.
With FakeBus now in its place,
Tests run smooth, a joyful race.
Mocking here, mocking there,
Simplified, we leap with care! 🐇✨

Warning

Rate limit exceeded

@JarbasAl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3266acf and 9220234.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

@github-actions github-actions bot added fix and removed fix labels Nov 21, 2024
Copy link

@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: 0

🧹 Outside diff range and nitpick comments (5)
test/backwards_compat/test_ocp.py (5)

Line range hint 8-13: Remove commented out imports.

These commented imports are no longer needed and should be removed for better code maintainability.

-# from ovos_plugin_common_play.ocp.mycroft_cps import MycroftAudioService
-# from mycroft.configuration import Configuration

Line range hint 47-65: Consider refactoring common test setup code.

The setUpClass method and message handling setup is duplicated across all three test classes. Consider creating a base test class to reduce code duplication.

class BaseOCPTest(unittest.TestCase):
    @classmethod
    @patch.object(Configuration, 'load_all_configs')
    def setUpClass(cls, mock) -> None:
        mock.return_value = BASE_CONF
        cls.bus = FakeBus()
        cls.bus.emitted_msgs = []

        def get_msg(msg):
            msg = json.loads(msg)
            msg.pop("context")
            cls.bus.emitted_msgs.append(msg)

        cls.bus.on("message", get_msg)

class TestOCPLoad(BaseOCPTest):
    # ... rest of the class

Also applies to: 89-107, 246-264


Line range hint 71-71: Document skip reasons in test methods.

Several tests are marked with @pytest.mark.skip without clear documentation explaining why they are skipped. Add comments explaining the skip reasons and any tracking issues.

-    @pytest.mark.skip
+    @pytest.mark.skip(reason="TODO: Document why this test is skipped and link to tracking issue")
     def test_native_ocp(self):

Also applies to: 187-187, 359-359, 403-403, 447-447


Line range hint 359-402: Consider using helper methods for message verification.

The test contains multiple repeated message structure verifications. Consider creating helper methods to make the tests more readable and maintainable.

def assert_message_sent(self, expected_msg):
    """Helper method to verify message was sent on the bus"""
    self.assertIn(expected_msg, self.bus.emitted_msgs)

def assert_play_messages(self, tracks, repeat=False, utterance=''):
    """Helper method to verify play-related messages"""
    expected = [
        {'type': 'mycroft.audio.service.play',
         'data': {'tracks': tracks, 'utterance': utterance, 'repeat': repeat}},
        {'type': 'ovos.common_play.playlist.clear', 'data': {}}
    ]
    for msg in expected:
        self.assert_message_sent(msg)

Line range hint 246-456: Consider adding error case test coverage.

The test suite primarily covers happy path scenarios. Consider adding test cases for:

  • Invalid track URIs
  • Network errors during playback
  • Invalid state transitions
  • Malformed message handling
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3266acf and 9220234.

📒 Files selected for processing (7)
  • test/backwards_compat/test_ocp.py (1 hunks)
  • test/end2end/minicroft.py (1 hunks)
  • test/integrationtests/common_query/test_continuous_dialog.py (1 hunks)
  • test/integrationtests/common_query/test_skill.py (1 hunks)
  • test/integrationtests/test_workshop.py (1 hunks)
  • test/unittests/test_skill_manager.py (0 hunks)
  • test/unittests/xformers.py (1 hunks)
💤 Files with no reviewable changes (1)
  • test/unittests/test_skill_manager.py
✅ Files skipped from review due to trivial changes (3)
  • test/end2end/minicroft.py
  • test/integrationtests/common_query/test_skill.py
  • test/unittests/xformers.py
🔇 Additional comments (4)
test/integrationtests/common_query/test_continuous_dialog.py (2)

5-5: LGTM! Good refactoring of test utilities.

The change appropriately moves test-specific message bus classes to a dedicated fakebus module while maintaining backward compatibility through aliasing.


5-5: Verify consistent import updates across test files.

Let's ensure this import change has been consistently applied across all test files using the message bus utilities.

✅ Verification successful

Import usage is consistent and correctly segregated between test types

The verification shows a clear and consistent pattern:

  • Integration tests correctly use FakeMessage from ovos_utils.fakebus
  • Unit tests and end-to-end tests appropriately use Message from ovos_bus_client

This segregation is intentional and correct:

  • Integration tests need the fake message bus utilities
  • Other test types require the actual message bus client
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining old imports and verify new import adoption
# Test 1: Check for any remaining old imports
echo "Checking for remaining old imports from messagebus..."
rg "from ovos_utils.messagebus import.*Message" "test/"

# Test 2: Verify adoption of new imports
echo "Verifying adoption of new fakebus imports..."
rg "from ovos_utils.fakebus import.*FakeMessage" "test/"

# Test 3: Check for potential missed Message imports
echo "Checking for other Message imports that might need updating..."
rg "import.*Message" "test/" --type py

Length of output: 2431

test/integrationtests/test_workshop.py (1)

7-7: LGTM! Import updated from deprecated module.

The change correctly updates the imports from the deprecated messagebus module to the new fakebus module while maintaining backward compatibility through aliasing.

Let's verify the deprecation status and usage patterns:

✅ Verification successful

Import change verified and consistent across codebase

The verification confirms:

  • No remaining deprecated imports from ovos_utils.messagebus
  • Consistent usage of new ovos_utils.fakebus imports across test files
  • The aliasing pattern (FakeMessage as Message) is used where needed
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other instances of deprecated imports and verify new import usage

# Check for any remaining deprecated imports
echo "Checking for remaining deprecated messagebus imports..."
rg "from ovos_utils.messagebus import (Message|FakeBus)"

# Verify consistent usage of new imports across tests
echo "Checking for new fakebus import pattern..."
rg "from ovos_utils.fakebus import"

Length of output: 907

test/backwards_compat/test_ocp.py (1)

20-20: LGTM! Import updated correctly.

The import has been properly updated from ovos_utils.messagebus to ovos_utils.fakebus as per the PR objectives.

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.13%. Comparing base (23f0bab) to head (9220234).
Report is 102 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #611      +/-   ##
==========================================
- Coverage   75.33%   73.13%   -2.21%     
==========================================
  Files          15       15              
  Lines        3094     1526    -1568     
==========================================
- Hits         2331     1116    -1215     
+ Misses        763      410     -353     
Flag Coverage Δ
end2end 56.48% <ø> (?)
unittests 49.34% <ø> (-26.00%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@JarbasAl JarbasAl merged commit 5c32b2b into dev Nov 21, 2024
7 of 8 checks passed
@JarbasAl JarbasAl deleted the deprecate/imports branch November 21, 2024 19:50
@coderabbitai coderabbitai bot mentioned this pull request Dec 6, 2024
@coderabbitai coderabbitai bot mentioned this pull request Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant