Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions sonic-thermalctld/tests/mock_swsscommon.py

This file was deleted.

4 changes: 4 additions & 0 deletions sonic-thermalctld/tests/mocked_libs/swsscommon/swsscommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from swsssdk import ConfigDBConnector, SonicDBConfig, SonicV2Connector

STATE_DB = ''
CHASSIS_STATE_DB = ''


class Table:
Expand All @@ -28,6 +29,9 @@ def get(self, key):
def get_size(self):
return (len(self.mock_dict))

def getKeys(self):
return list(self.mock_dict.keys())


class FieldValuePairs:
fv_dict = {}
Expand Down
25 changes: 18 additions & 7 deletions sonic-thermalctld/tests/test_thermalctld.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import os
import sys
import multiprocessing
from imp import load_source # TODO: Replace with importlib once we no longer need to support Python 2
import importlib.machinery
import importlib.util

from unittest import mock

# TODO: Clean this up once we no longer need to support Python 2
if sys.version_info.major == 3:
from unittest import mock
else:
import mock

import pytest
tests_path = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -25,7 +23,10 @@
from sonic_py_common import daemon_base

from .mock_platform import MockChassis, MockFan, MockModule, MockPsu, MockSfp, MockThermal
from .mock_swsscommon import Table
from .mocked_libs.swsscommon import swsscommon

Table = swsscommon.Table
FieldValuePairs = swsscommon.FieldValuePairs

daemon_base.db_connect = mock.MagicMock()

Expand All @@ -34,6 +35,16 @@
scripts_path = os.path.join(modules_path, 'scripts')
sys.path.insert(0, modules_path)

# Replacement for imp.load_source from the Python3.12 docs:
# https://docs.python.org/3/whatsnew/3.12.html#imp
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
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)
Comment thread
fraserg-arista marked this conversation as resolved.
return module

load_source('thermalctld', os.path.join(scripts_path, 'thermalctld'))
import thermalctld

Expand Down
Loading