-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from unittest.mock import patch | ||
from mock import MagicMock | ||
from io import BytesIO | ||
import pytest | ||
import traceback | ||
import random | ||
from sonic_platform_base.sonic_xcvr.api.public.cmis import CmisApi | ||
from sonic_platform_base.sonic_xcvr.api.credo.aec_800g import CmisAec800gApi | ||
from sonic_platform_base.sonic_xcvr.mem_maps.public.cmis import CmisMemMap | ||
from sonic_platform_base.sonic_xcvr.mem_maps.credo.aec_800g import CmisAec800gMemMap | ||
from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom | ||
from sonic_platform_base.sonic_xcvr.codes.public.cmis import CmisCodes | ||
from sonic_platform_base.sonic_xcvr.codes.credo.aec_800g import CmisAec800gCodes | ||
from sonic_platform_base.sonic_xcvr.codes.public.sff8024 import Sff8024 | ||
from sonic_platform_base.sonic_xcvr.fields import consts | ||
from sonic_platform_base.sonic_xcvr.xcvr_api_factory import XcvrApiFactory | ||
|
||
class BytesMock(bytes): | ||
def decode(self, encoding='utf-8', errors='strict'): | ||
return 'DecodedCredo' | ||
|
||
class TestXcvrApiFactory(object): | ||
read_eeprom = MagicMock | ||
write_eeprom = MagicMock | ||
api = XcvrApiFactory(read_eeprom, write_eeprom) | ||
|
||
def test_get_vendor_name(self): | ||
self.api.reader = MagicMock() | ||
self.api.reader.return_value = b'Credo' | ||
with patch.object(BytesMock, 'decode', return_value='DecodedCredo'): | ||
result = self.api._get_vendor_name() | ||
assert result == 'Credo'.strip() | ||
|
||
def test_get_vendor_part_num(self): | ||
self.api.reader = MagicMock() | ||
self.api.reader.return_value = b'CAC81X321M2MC1MS' | ||
with patch.object(BytesMock, 'decode', return_value='DecodedCAC81X321M2MC1MS'): | ||
result = self.api._get_vendor_part_num() | ||
assert result == 'CAC81X321M2MC1MS'.strip() | ||
|
||
def test_create_xcvrd_api(self): | ||
self._get_id = MagicMock() | ||
self._get_id.side_effect = 0x18 | ||
self._get_vendor_name= MagicMock() | ||
self._get_vendor_name.side_effect = 'Credo' | ||
self._get_vendor_part_num = MagicMock() | ||
self._get_vendor_part_num.side_effect = 'CAC81X321M2MC1MS' | ||
CmisAec800gCodes = MagicMock() | ||
CmisAec800gMemMap = MagicMock() | ||
XcvrEeprom = MagicMock() | ||
CmisAec800gApi = MagicMock() | ||
self.api.create_xcvr_api() |