Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for get_chassis_info
Browse files Browse the repository at this point in the history
alexrallen committed May 12, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9aff9c7 commit 19b0314
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/sonic-py-common/tests/device_info_test.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

from sonic_py_common import device_info

from . import mock_swsssdk

# TODO: Remove this if/else block once we no longer support Python 2
if sys.version_info.major == 3:
@@ -49,7 +50,6 @@
'onie_kernel_version': '4.10.11'
}


class TestDeviceInfo(object):
@classmethod
def setup_class(cls):
@@ -70,6 +70,14 @@ def test_get_platform(self):
result = device_info.get_platform()
assert result == "x86_64-mlnx_msn2700-r0"

def test_get_chassis_info(self):
with mock.patch("device_info.swsssdk", new=mock_swsssdk):
result = device_info.get_chassis_info()
truth = {"serial": self.TEST_SERIAL,
"model": self.TEST_MODEL,
"revision": self.TEST_REV}
assert result == truth

@classmethod
def teardown_class(cls):
print("TEARDOWN")
13 changes: 13 additions & 0 deletions src/sonic-py-common/tests/mock_swsssdk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class SonicV2Connector:

def __init__(self):
self.STATE_DB = 'STATE_DB'
self.data = {"serial": self.TEST_SERIAL,
"model": self.TEST_MODEL,
"revision": self.TEST_REV}

def connect(self, db):
pass

def get(self, db, table, field):
self.data.get(field, "N/A")

0 comments on commit 19b0314

Please sign in to comment.