Skip to content

Commit a305336

Browse files
committed
Fix unit test for device_info
1 parent 19b0314 commit a305336

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/sonic-py-common/sonic_py_common/device_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def get_chassis_info():
6767

6868
try:
6969
# Init statedb connection
70-
db = swsscommon.SonicV2Connector()
70+
db = SonicV2Connector()
7171
db.connect(db.STATE_DB)
7272
table = CHASSIS_INFO_TABLE.format(1)
7373

src/sonic-py-common/tests/device_info_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from sonic_py_common import device_info
1313

14-
from . import mock_swsssdk
14+
from .mock_swsssdk import SonicV2Connector
1515

1616
# TODO: Remove this if/else block once we no longer support Python 2
1717
if sys.version_info.major == 3:
@@ -71,11 +71,11 @@ def test_get_platform(self):
7171
assert result == "x86_64-mlnx_msn2700-r0"
7272

7373
def test_get_chassis_info(self):
74-
with mock.patch("device_info.swsssdk", new=mock_swsssdk):
74+
with mock.patch("sonic_py_common.device_info.SonicV2Connector", new=SonicV2Connector):
7575
result = device_info.get_chassis_info()
76-
truth = {"serial": self.TEST_SERIAL,
77-
"model": self.TEST_MODEL,
78-
"revision": self.TEST_REV}
76+
truth = {"serial": SonicV2Connector.TEST_SERIAL,
77+
"model": SonicV2Connector.TEST_MODEL,
78+
"revision": SonicV2Connector.TEST_REV}
7979
assert result == truth
8080

8181
@classmethod

src/sonic-py-common/tests/mock_swsssdk.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
class SonicV2Connector:
2+
TEST_SERIAL = "MT1822K07815"
3+
TEST_MODEL = "MSN2700-CS2FO"
4+
TEST_REV = "A1"
25

36
def __init__(self):
47
self.STATE_DB = 'STATE_DB'
@@ -10,4 +13,4 @@ def connect(self, db):
1013
pass
1114

1215
def get(self, db, table, field):
13-
self.data.get(field, "N/A")
16+
return self.data.get(field, "N/A")

0 commit comments

Comments
 (0)