ruff: replace isort with ruff +TPU (#17684)
* ruff: replace isort with ruff
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fixing & imports
* lines in warning test
* docs
* fix enum import
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fixing
* import
* fix lines
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* type ClusterEnvironment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-09-26 15:54:55 +00:00
|
|
|
from unittest import TestCase, mock
|
2022-08-23 19:48:22 +00:00
|
|
|
|
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()
|