1
1
from mock import MagicMock , patch
2
+ import pytest
3
+
2
4
3
5
from sonic_platform_base .sonic_xcvr .api .public .sff8636 import Sff8636Api
4
6
from sonic_platform_base .sonic_xcvr .codes .public .sff8636 import Sff8636Codes
5
7
from sonic_platform_base .sonic_xcvr .mem_maps .public .sff8636 import Sff8636MemMap
6
8
from sonic_platform_base .sonic_xcvr .xcvr_eeprom import XcvrEeprom
9
+ from sonic_platform_base .sonic_xcvr .fields import consts
7
10
8
11
class TestSff8636 (object ):
9
12
codes = Sff8636Codes
@@ -52,6 +55,36 @@ def test_api(self):
52
55
self .api .get_lpmode_support ()
53
56
self .api .get_power_override_support ()
54
57
58
+ @pytest .mark .parametrize ("mock_response, expected" , [
59
+ (bytearray ([0x0 ]), "Power Class 1 Module (1.5W max.)" ),
60
+ (bytearray ([0x40 ]), "Power Class 2 Module (2.0W max.)" ),
61
+ (bytearray ([0x80 ]), "Power Class 3 Module (2.5W max.)" ),
62
+ (bytearray ([0xC0 ]), "Power Class 4 Module (3.5W max.)" ),
63
+ (bytearray ([0xC1 ]), "Power Class 5 Module (4.0W max.)" ),
64
+ (bytearray ([0xC2 ]), "Power Class 6 Module (4.5W max.)" ),
65
+ (bytearray ([0xC3 ]), "Power Class 7 Module (5.0W max.)" ),
66
+ (bytearray ([0x20 ]), "Power Class 8 Module" )
67
+ ])
68
+ def test_power_class (self , mock_response , expected ):
69
+ self .api .xcvr_eeprom .reader = MagicMock ()
70
+ self .api .xcvr_eeprom .reader .return_value = mock_response
71
+ result = self .api .xcvr_eeprom .read (consts .POWER_CLASS_FIELD )
72
+ assert result == expected
73
+
74
+ @pytest .mark .parametrize ("mock_response, expected" , [
75
+ (bytearray ([0x02 , 0x0 ]), "Longwave laser (LC)" ),
76
+ (bytearray ([0x01 , 0x0 ]), "Electrical inter-enclosure (EN)" ),
77
+ (bytearray ([0x0 , 0x80 ]), "Electrical intra-enclosure" ),
78
+ (bytearray ([0x0 , 0x40 ]), "Shortwave laser w/o OFC (SN)" ),
79
+ (bytearray ([0x0 , 0x20 ]), "Shortwave laser w OFC (SL)" ),
80
+ (bytearray ([0x0 , 0x10 ]), "Longwave Laser (LL)" )
81
+ ])
82
+ def test_fiber_channel_transmitter_tech (self , mock_response , expected ):
83
+ self .api .xcvr_eeprom .reader = MagicMock ()
84
+ self .api .xcvr_eeprom .reader .return_value = mock_response
85
+ result = self .api .xcvr_eeprom .read (consts .FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD )
86
+ assert result == expected
87
+
55
88
def test_is_copper (self ):
56
89
with patch .object (self .api , 'xcvr_eeprom' ) as mock_eeprom :
57
90
mock_eeprom .read = MagicMock ()
@@ -71,3 +104,4 @@ def test_simulate_copper(self):
71
104
assert not self .api .get_rx_power_support ()
72
105
assert not self .api .get_temperature_support ()
73
106
assert not self .api .get_voltage_support ()
107
+
0 commit comments