lightning/tests/tests_app/utilities/test_log_helpers.py

24 lines
1.0 KiB
Python
Raw Normal View History

[CLI] Adding opportunity to see basic cluster logs (#14334) * pinning starsessions * pinning starsessions * adding strict back to requirements.txt * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Duplicated * Basic implementation * Basic implementation * Basic implementation * Basic implementation * Common things moved to log helpers file * Decomposing logs reader classes for reusing * Setting colors for log levels * Manifest trimming * Changes added to CHANGELOG * Prettifications * Prettifications * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Logs function name change * Logs function name change * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * attempt to fix the pydanitc import * Tests + command name fixes * Extending tests * Adding limit argument * Unmerging CI fix * Unmerging CI fix * Adding fields for errors * Adding log level fixed field width * Adding absent typing + exeptions raising * Adding socket error logging * Addressing comments on cluster list function return value * Addressing comments on adding e2e tests * Adding version range for arrow package in reqs * New unit tests * arrow time parsing callback modified + unit tests * helpers updated * helpers updated * helpers updated * One more test * CMD test fix * CMD test fix * CMD test fix * CMD test fix * CMD test fix * LightningClient mocking * Flaky test removed Co-authored-by: hhsecond <sherin@grid.ai> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2022-08-23 19:48:22 +00:00
from unittest import mock, TestCase
from lightning_app.utilities.log_helpers import _error_callback
class TestErrorCallback(TestCase):
def test_known_error(self):
websocket = mock.Mock()
with self.assertLogs("lightning_app.utilities.log_helpers") as captured:
_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()
with self.assertLogs("lightning_app.utilities.log_helpers") as captured:
_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())