2022-08-23 19:48:22 +00:00
|
|
|
from unittest import mock, TestCase
|
|
|
|
|
2023-02-01 11:07:00 +00:00
|
|
|
from lightning.app.utilities.log_helpers import _error_callback
|
2022-08-23 19:48:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestErrorCallback(TestCase):
|
|
|
|
def test_known_error(self):
|
|
|
|
websocket = mock.Mock()
|
2023-02-01 11:07:00 +00:00
|
|
|
with self.assertLogs("lightning.app.utilities.log_helpers") as captured:
|
2022-08-23 19:48:22 +00:00
|
|
|
_error_callback(websocket, ValueError())
|
|
|
|
# check that there is only one log message
|
2023-05-04 15:50:39 +00:00
|
|
|
assert len(captured.records) == 1
|
2022-08-23 19:48:22 +00:00
|
|
|
# and it contains the error message expected
|
2023-05-04 15:50:39 +00:00
|
|
|
assert "Error while reading logs (Malformed date format)" in captured.records[0].getMessage()
|
2022-08-23 19:48:22 +00:00
|
|
|
|
|
|
|
def test_unknown_error(self):
|
|
|
|
websocket = mock.Mock()
|
2023-02-01 11:07:00 +00:00
|
|
|
with self.assertLogs("lightning.app.utilities.log_helpers") as captured:
|
2022-08-23 19:48:22 +00:00
|
|
|
_error_callback(websocket, IOError())
|
|
|
|
# check that there is only one log message
|
2023-05-04 15:50:39 +00:00
|
|
|
assert len(captured.records) == 1
|
2022-08-23 19:48:22 +00:00
|
|
|
# and it contains the error message expected
|
2023-05-04 15:50:39 +00:00
|
|
|
assert "Error while reading logs (Unknown)" in captured.records[0].getMessage()
|