Skip to content

Commit 9297a29

Browse files
authored
Mock path early so it will applied to sonic_py_common, mock platform_chassis (sonic-net#188)
#### Description Following sonic-net/sonic-platform-daemons#187 to fix the same issue with other packages #### Motivation and Context This is blocking sonic-net#7655 #### How Has This Been Tested? Unit test
1 parent 9ba52a2 commit 9297a29

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

sonic-psud/tests/mocked_libs/swsscommon/swsscommon.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Mock implementation of swsscommon package for unit testing
33
'''
44

5+
from swsssdk import ConfigDBConnector, SonicDBConfig, SonicV2Connector
6+
57
STATE_DB = ''
68

79

sonic-psud/tests/test_DaemonPsud.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@
1010
from unittest import mock
1111
else:
1212
import mock
13-
from sonic_py_common import daemon_base
1413

1514
from .mock_platform import MockChassis, MockFan, MockPsu
1615

1716
SYSLOG_IDENTIFIER = 'psud_test'
1817
NOT_AVAILABLE = 'N/A'
1918

20-
daemon_base.db_connect = mock.MagicMock()
2119

2220
tests_path = os.path.dirname(os.path.abspath(__file__))
2321

2422
# Add mocked_libs path so that the file under test can load mocked modules from there
2523
mocked_libs_path = os.path.join(tests_path, "mocked_libs")
2624
sys.path.insert(0, mocked_libs_path)
2725

26+
from sonic_py_common import daemon_base
27+
daemon_base.db_connect = mock.MagicMock()
28+
2829
# Add path to the file under test so that we can load it
2930
modules_path = os.path.dirname(tests_path)
3031
scripts_path = os.path.join(modules_path, "scripts")

sonic-psud/tests/test_psud.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import mock
1212
from sonic_py_common import daemon_base
1313

14-
from .mock_platform import MockPsu
14+
from .mock_platform import MockPsu, MockChassis
1515

1616
tests_path = os.path.dirname(os.path.abspath(__file__))
1717

@@ -179,6 +179,7 @@ def test_log_on_status_changed():
179179
mock_logger.log_warning.assert_called_with(abnormal_log)
180180

181181

182+
@mock.patch('psud.platform_chassis', mock.MagicMock())
182183
@mock.patch('psud.DaemonPsud.run')
183184
def test_main(mock_run):
184185
mock_run.return_value = False

sonic-syseepromd/tests/mocked_libs/swsscommon/swsscommon.py

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Mock implementation of swsscommon package for unit testing
33
'''
44

5+
from swsssdk import ConfigDBConnector, SonicDBConfig, SonicV2Connector
6+
57
STATE_DB = ''
68

79

@@ -23,6 +25,9 @@ def get(self, key):
2325
return self.mock_dict[key]
2426
return None
2527

28+
def get_size(self):
29+
return (len(self.mock_dict))
30+
2631

2732
class FieldValuePairs:
2833
fv_dict = {}

sonic-syseepromd/tests/test_syseepromd.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
from unittest import mock
1010
else:
1111
import mock
12-
from sonic_py_common import daemon_base
1312

1413
SYSLOG_IDENTIFIER = 'syseepromd_test'
1514
NOT_AVAILABLE = 'N/A'
1615

17-
daemon_base.db_connect = mock.MagicMock()
18-
1916
tests_path = os.path.dirname(os.path.abspath(__file__))
2017

2118
# Add mocked_libs path so that the file under test can load mocked modules from there
2219
mocked_libs_path = os.path.join(tests_path, 'mocked_libs')
2320
sys.path.insert(0, mocked_libs_path)
2421

22+
from sonic_py_common import daemon_base
23+
daemon_base.db_connect = mock.MagicMock()
24+
2525
# Add path to the file under test so that we can load it
2626
modules_path = os.path.dirname(tests_path)
2727
scripts_path = os.path.join(modules_path, 'scripts')

0 commit comments

Comments
 (0)