|
| 1 | +from unittest.mock import mock_open |
1 | 2 | from mock import MagicMock |
2 | 3 | from mock import patch |
3 | 4 | import pytest |
@@ -79,3 +80,36 @@ def test_get_vdm_unfreeze_status(self, mock_response1, mock_response2, expected) |
79 | 80 | result = self.sfp_optoe_api.get_vdm_unfreeze_status() |
80 | 81 | assert result == expected |
81 | 82 |
|
| 83 | + @patch("builtins.open", new_callable=mock_open) |
| 84 | + @patch.object(SfpOptoeBase, 'get_eeprom_path') |
| 85 | + def test_set_optoe_write_timeout_success(self, mock_get_eeprom_path, mock_open): |
| 86 | + mock_get_eeprom_path.return_value = "/sys/bus/i2c/devices/1-0050/eeprom" |
| 87 | + expected_path = "/sys/bus/i2c/devices/1-0050/write_timeout" |
| 88 | + expected_timeout = 1 |
| 89 | + |
| 90 | + self.sfp_optoe_api.set_optoe_write_timeout(expected_timeout) |
| 91 | + |
| 92 | + mock_open.assert_called_once_with(expected_path, mode='w') |
| 93 | + mock_open().write.assert_called_once_with(str(expected_timeout)) |
| 94 | + |
| 95 | + @patch("builtins.open", new_callable=mock_open) |
| 96 | + @patch.object(SfpOptoeBase, 'get_eeprom_path') |
| 97 | + def test_set_optoe_write_timeout_ioerror(self, mock_get_eeprom_path, mock_open): |
| 98 | + mock_get_eeprom_path.return_value = "/sys/bus/i2c/devices/1-0050/eeprom" |
| 99 | + expected_timeout = 1 |
| 100 | + mock_open.side_effect = IOError |
| 101 | + |
| 102 | + self.sfp_optoe_api.set_optoe_write_timeout(expected_timeout) |
| 103 | + |
| 104 | + mock_open.assert_called() |
| 105 | + |
| 106 | + @patch("builtins.open", new_callable=mock_open) |
| 107 | + @patch.object(SfpOptoeBase, 'get_eeprom_path') |
| 108 | + def test_set_optoe_write_timeout_oserror(self, mock_get_eeprom_path, mock_open): |
| 109 | + mock_get_eeprom_path.return_value = "/sys/bus/i2c/devices/1-0050/eeprom" |
| 110 | + expected_timeout = 1 |
| 111 | + mock_open.side_effect = OSError |
| 112 | + |
| 113 | + self.sfp_optoe_api.set_optoe_write_timeout(expected_timeout) |
| 114 | + |
| 115 | + mock_open.assert_called() |
0 commit comments