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
|
|
|
|
self.assertEqual(len(captured.records), 1)
|
|
|
|
# and it contains the error message expected
|
|
|
|
self.assertIn("Error while reading logs (Malformed date format)", captured.records[0].getMessage())
|
|
|
|
|
|
|
|
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
|
|
|
|
self.assertEqual(len(captured.records), 1)
|
|
|
|
# and it contains the error message expected
|
|
|
|
self.assertIn("Error while reading logs (Unknown)", captured.records[0].getMessage())
|