From e57bac6da82af462c6638159fc196a0bdccae680 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:03:03 +0200 Subject: [PATCH] Fix confusing-with-statement pylint warnings (#119364) --- tests/components/dsmr/test_config_flow.py | 9 +++++---- tests/components/rfxtrx/test_config_flow.py | 9 +++++---- tests/components/usb/test_init.py | 9 +++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/components/dsmr/test_config_flow.py b/tests/components/dsmr/test_config_flow.py index 791797f7dcd..711b29f4ae0 100644 --- a/tests/components/dsmr/test_config_flow.py +++ b/tests/components/dsmr/test_config_flow.py @@ -519,16 +519,17 @@ def test_get_serial_by_id_no_dir() -> None: def test_get_serial_by_id() -> None: """Test serial by id conversion.""" - p1 = patch("os.path.isdir", MagicMock(return_value=True)) - p2 = patch("os.scandir") def _realpath(path): if path is sentinel.matched_link: return sentinel.path return sentinel.serial_link_path - p3 = patch("os.path.realpath", side_effect=_realpath) - with p1 as is_dir_mock, p2 as scan_mock, p3: + with ( + patch("os.path.isdir", MagicMock(return_value=True)) as is_dir_mock, + patch("os.scandir") as scan_mock, + patch("os.path.realpath", side_effect=_realpath), + ): res = config_flow.get_serial_by_id(sentinel.path) assert res is sentinel.path assert is_dir_mock.call_count == 1 diff --git a/tests/components/rfxtrx/test_config_flow.py b/tests/components/rfxtrx/test_config_flow.py index fd1cfbb09fd..b61440c31b6 100644 --- a/tests/components/rfxtrx/test_config_flow.py +++ b/tests/components/rfxtrx/test_config_flow.py @@ -900,16 +900,17 @@ def test_get_serial_by_id_no_dir() -> None: def test_get_serial_by_id() -> None: """Test serial by id conversion.""" - p1 = patch("os.path.isdir", MagicMock(return_value=True)) - p2 = patch("os.scandir") def _realpath(path): if path is sentinel.matched_link: return sentinel.path return sentinel.serial_link_path - p3 = patch("os.path.realpath", side_effect=_realpath) - with p1 as is_dir_mock, p2 as scan_mock, p3: + with ( + patch("os.path.isdir", MagicMock(return_value=True)) as is_dir_mock, + patch("os.scandir") as scan_mock, + patch("os.path.realpath", side_effect=_realpath), + ): res = config_flow.get_serial_by_id(sentinel.path) assert res is sentinel.path assert is_dir_mock.call_count == 1 diff --git a/tests/components/usb/test_init.py b/tests/components/usb/test_init.py index c3f7817527c..ce7484a811c 100644 --- a/tests/components/usb/test_init.py +++ b/tests/components/usb/test_init.py @@ -771,16 +771,17 @@ def test_get_serial_by_id_no_dir() -> None: def test_get_serial_by_id() -> None: """Test serial by id conversion.""" - p1 = patch("os.path.isdir", MagicMock(return_value=True)) - p2 = patch("os.scandir") def _realpath(path): if path is sentinel.matched_link: return sentinel.path return sentinel.serial_link_path - p3 = patch("os.path.realpath", side_effect=_realpath) - with p1 as is_dir_mock, p2 as scan_mock, p3: + with ( + patch("os.path.isdir", MagicMock(return_value=True)) as is_dir_mock, + patch("os.scandir") as scan_mock, + patch("os.path.realpath", side_effect=_realpath), + ): res = usb.get_serial_by_id(sentinel.path) assert res is sentinel.path assert is_dir_mock.call_count == 1