Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chiourung committed Aug 9, 2023
1 parent fdd1633 commit ba1a666
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/sonic_xcvr/test_sff8436.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,66 @@ def test_set_lpmode(self):
self.api.get_lpmode_support.return_value = False
self.api.get_power_override_support.return_value = False
assert not self.api.set_lpmode(True)

@pytest.mark.parametrize("mock_response, expected",[
(
[
[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
0,
50,
3.3,
[70, 70, 70, 70],
[0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1],
True, True, True, True, True, True
],
{
'temperature': 50,
'voltage': 3.3,
'tx1power': -10.0, 'tx2power': -10.0, 'tx3power': -10.0, 'tx4power': -10.0,
'rx1power': -10.0, 'rx2power': -10.0, 'rx3power': -10.0, 'rx4power': -10.0,
'tx1bias': 70, 'tx2bias': 70, 'tx3bias': 70, 'tx4bias': 70,
'rx_los': False,
'tx_fault': False,
'tx_disable': False,
'tx_disabled_channel': 0,
}
)
])
def test_get_transceiver_bulk_status(self, mock_response, expected):
self.api.get_rx_los = MagicMock()
self.api.get_rx_los.return_value = mock_response[0]
self.api.get_tx_fault = MagicMock()
self.api.get_tx_fault.return_value = mock_response[1]
self.api.get_tx_disable = MagicMock()
self.api.get_tx_disable.return_value = mock_response[2]
self.api.get_tx_disable_channel = MagicMock()
self.api.get_tx_disable_channel.return_value = mock_response[3]
self.api.get_module_temperature = MagicMock()
self.api.get_module_temperature.return_value = mock_response[4]
self.api.get_voltage = MagicMock()
self.api.get_voltage.return_value = mock_response[5]
self.api.get_tx_bias = MagicMock()
self.api.get_tx_bias.return_value = mock_response[6]
self.api.get_rx_power = MagicMock()
self.api.get_rx_power.return_value = mock_response[7]
self.api.get_tx_power = MagicMock()
self.api.get_tx_power.return_value = mock_response[8]
self.api.get_rx_los_support = MagicMock()
self.api.get_rx_los_support.return_value = mock_response[9]
self.api.get_tx_fault_support = MagicMock()
self.api.get_tx_fault_support.return_value = mock_response[10]
self.api.get_tx_disable_support = MagicMock()
self.api.get_tx_disable_support.return_value = mock_response[11]
self.api.get_tx_bias_support = MagicMock()
self.api.get_tx_bias_support.return_value = mock_response[12]
self.api.get_tx_power_support = MagicMock()
self.api.get_tx_power_support.return_value = mock_response[13]
self.api.get_rx_power_support = MagicMock()
self.api.get_rx_power_support.return_value = mock_response[14]
result = self.api.get_transceiver_bulk_status()
assert result == expected


62 changes: 62 additions & 0 deletions tests/sonic_xcvr/test_sff8472.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,65 @@ def test_fiber_channel_transmitter_tech(self, mock_response, expected):
self.api.xcvr_eeprom.reader.return_value = mock_response
result = self.api.xcvr_eeprom.read(consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD)
assert result == expected

@pytest.mark.parametrize("mock_response, expected",[
(
[
[False],
[False],
[False],
0,
50,
3.3,
[70],
[0.1],
[0.1],
True, True, True, True, True, True
],
{
'temperature': 50,
'voltage': 3.3,
'tx1power': -10.0, 'tx2power': 'N/A', 'tx3power': 'N/A', 'tx4power': 'N/A',
'rx1power': -10.0, 'rx2power': 'N/A', 'rx3power': 'N/A', 'rx4power': 'N/A',
'tx1bias': 70, 'tx2bias': 'N/A', 'tx3bias': 'N/A', 'tx4bias': 'N/A',
'rx_los': False,
'tx_fault': False,
'tx_disable': False,
'tx_disabled_channel': 0,
}
)
])
def test_get_transceiver_bulk_status(self, mock_response, expected):
self.api.get_rx_los = MagicMock()
self.api.get_rx_los.return_value = mock_response[0]
self.api.get_tx_fault = MagicMock()
self.api.get_tx_fault.return_value = mock_response[1]
self.api.get_tx_disable = MagicMock()
self.api.get_tx_disable.return_value = mock_response[2]
self.api.get_tx_disable_channel = MagicMock()
self.api.get_tx_disable_channel.return_value = mock_response[3]
self.api.get_module_temperature = MagicMock()
self.api.get_module_temperature.return_value = mock_response[4]
self.api.get_voltage = MagicMock()
self.api.get_voltage.return_value = mock_response[5]
self.api.get_tx_bias = MagicMock()
self.api.get_tx_bias.return_value = mock_response[6]
self.api.get_rx_power = MagicMock()
self.api.get_rx_power.return_value = mock_response[7]
self.api.get_tx_power = MagicMock()
self.api.get_tx_power.return_value = mock_response[8]
self.api.get_rx_los_support = MagicMock()
self.api.get_rx_los_support.return_value = mock_response[9]
self.api.get_tx_fault_support = MagicMock()
self.api.get_tx_fault_support.return_value = mock_response[10]
self.api.get_tx_disable_support = MagicMock()
self.api.get_tx_disable_support.return_value = mock_response[11]
self.api.get_tx_bias_support = MagicMock()
self.api.get_tx_bias_support.return_value = mock_response[12]
self.api.get_tx_power_support = MagicMock()
self.api.get_tx_power_support.return_value = mock_response[13]
self.api.get_rx_power_support = MagicMock()
self.api.get_rx_power_support.return_value = mock_response[14]
result = self.api.get_transceiver_bulk_status()
assert result == expected

61 changes: 61 additions & 0 deletions tests/sonic_xcvr/test_sff8636.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,64 @@ def test_set_lpmode(self):
self.api.get_power_override_support.return_value = False
assert not self.api.set_lpmode(True)

@pytest.mark.parametrize("mock_response, expected",[
(
[
[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
0,
50,
3.3,
[70, 70, 70, 70],
[0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1],
True, True, True, True, True, True
],
{
'temperature': 50,
'voltage': 3.3,
'tx1power': -10.0, 'tx2power': -10.0, 'tx3power': -10.0, 'tx4power': -10.0,
'rx1power': -10.0, 'rx2power': -10.0, 'rx3power': -10.0, 'rx4power': -10.0,
'tx1bias': 70, 'tx2bias': 70, 'tx3bias': 70, 'tx4bias': 70,
'rx_los': False,
'tx_fault': False,
'tx_disable': False,
'tx_disabled_channel': 0,
}
)
])
def test_get_transceiver_bulk_status(self, mock_response, expected):
self.api.get_rx_los = MagicMock()
self.api.get_rx_los.return_value = mock_response[0]
self.api.get_tx_fault = MagicMock()
self.api.get_tx_fault.return_value = mock_response[1]
self.api.get_tx_disable = MagicMock()
self.api.get_tx_disable.return_value = mock_response[2]
self.api.get_tx_disable_channel = MagicMock()
self.api.get_tx_disable_channel.return_value = mock_response[3]
self.api.get_module_temperature = MagicMock()
self.api.get_module_temperature.return_value = mock_response[4]
self.api.get_voltage = MagicMock()
self.api.get_voltage.return_value = mock_response[5]
self.api.get_tx_bias = MagicMock()
self.api.get_tx_bias.return_value = mock_response[6]
self.api.get_rx_power = MagicMock()
self.api.get_rx_power.return_value = mock_response[7]
self.api.get_tx_power = MagicMock()
self.api.get_tx_power.return_value = mock_response[8]
self.api.get_rx_los_support = MagicMock()
self.api.get_rx_los_support.return_value = mock_response[9]
self.api.get_tx_fault_support = MagicMock()
self.api.get_tx_fault_support.return_value = mock_response[10]
self.api.get_tx_disable_support = MagicMock()
self.api.get_tx_disable_support.return_value = mock_response[11]
self.api.get_tx_bias_support = MagicMock()
self.api.get_tx_bias_support.return_value = mock_response[12]
self.api.get_tx_power_support = MagicMock()
self.api.get_tx_power_support.return_value = mock_response[13]
self.api.get_rx_power_support = MagicMock()
self.api.get_rx_power_support.return_value = mock_response[14]
result = self.api.get_transceiver_bulk_status()
assert result == expected

0 comments on commit ba1a666

Please sign in to comment.