Skip to content

Conversation

@fraserg-arista
Copy link

Description

  • remove duplicated code for mocking swsscommon
  • add missing method to mocked swsscommon.Table
  • remove a deprecated import

Motivation and Context

Fixes exceptions which produce warnings (and harm test coverage) when running thermalctld tests.

How Has This Been Tested?

Ran thermalctld tests, observed no more warnings.

Add a missing method, remove duplicate code, remove a deprecated import.

Signed-off-by: Fraser Gordon <[email protected]>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vvolam vvolam requested a review from Copilot October 31, 2025 17:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modernizes the test code by removing Python 2 compatibility support and consolidating duplicate mock implementations.

  • Removes deprecated imp.load_source in favor of importlib (Python 3.12+ compatible)
  • Eliminates Python 2/3 conditional imports for the mock module
  • Consolidates duplicate mock code by moving it to a shared location

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
sonic-thermalctld/tests/test_thermalctld.py Removes Python 2 compatibility code and replaces deprecated imp.load_source with modern importlib implementation
sonic-thermalctld/tests/mocked_libs/swsscommon/swsscommon.py Adds missing constants and getKeys() method to the shared mock implementation
sonic-thermalctld/tests/mock_swsscommon.py Consolidates duplicate code by importing from the shared mock library instead of duplicating class definitions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
module = importlib.util.module_from_spec(spec)
sys.modules[module.__name__] = module
loader.exec_module(module)
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

The load_source function does not return the loaded module. Add return module at the end of the function, as the original imp.load_source returned the loaded module object.

Suggested change
loader.exec_module(module)
loader.exec_module(module)
return module

Copilot uses AI. Check for mistakes.

def get_size(self):
return (len(self.mock_dict))

Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

Trailing whitespace on line 31 should be removed to maintain code cleanliness.

Suggested change

Copilot uses AI. Check for mistakes.

STATE_DB = ''
CHASSIS_STATE_DB = ''
from .mocked_libs.swsscommon import swsscommon
Copy link
Contributor

Choose a reason for hiding this comment

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

Move these 3 lines of code directly to test_thermalctld.py as the file size is reduced now

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