Fix confusing-with-statement pylint warnings (#119364)

This commit is contained in:
epenet 2024-06-11 15:03:03 +02:00 committed by GitHub
parent 1974ea4fdd
commit e57bac6da8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 12 deletions

View file

@ -519,16 +519,17 @@ def test_get_serial_by_id_no_dir() -> None:
def test_get_serial_by_id() -> None: def test_get_serial_by_id() -> None:
"""Test serial by id conversion.""" """Test serial by id conversion."""
p1 = patch("os.path.isdir", MagicMock(return_value=True))
p2 = patch("os.scandir")
def _realpath(path): def _realpath(path):
if path is sentinel.matched_link: if path is sentinel.matched_link:
return sentinel.path return sentinel.path
return sentinel.serial_link_path return sentinel.serial_link_path
p3 = patch("os.path.realpath", side_effect=_realpath) with (
with p1 as is_dir_mock, p2 as scan_mock, p3: 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) res = config_flow.get_serial_by_id(sentinel.path)
assert res is sentinel.path assert res is sentinel.path
assert is_dir_mock.call_count == 1 assert is_dir_mock.call_count == 1

View file

@ -900,16 +900,17 @@ def test_get_serial_by_id_no_dir() -> None:
def test_get_serial_by_id() -> None: def test_get_serial_by_id() -> None:
"""Test serial by id conversion.""" """Test serial by id conversion."""
p1 = patch("os.path.isdir", MagicMock(return_value=True))
p2 = patch("os.scandir")
def _realpath(path): def _realpath(path):
if path is sentinel.matched_link: if path is sentinel.matched_link:
return sentinel.path return sentinel.path
return sentinel.serial_link_path return sentinel.serial_link_path
p3 = patch("os.path.realpath", side_effect=_realpath) with (
with p1 as is_dir_mock, p2 as scan_mock, p3: 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) res = config_flow.get_serial_by_id(sentinel.path)
assert res is sentinel.path assert res is sentinel.path
assert is_dir_mock.call_count == 1 assert is_dir_mock.call_count == 1

View file

@ -771,16 +771,17 @@ def test_get_serial_by_id_no_dir() -> None:
def test_get_serial_by_id() -> None: def test_get_serial_by_id() -> None:
"""Test serial by id conversion.""" """Test serial by id conversion."""
p1 = patch("os.path.isdir", MagicMock(return_value=True))
p2 = patch("os.scandir")
def _realpath(path): def _realpath(path):
if path is sentinel.matched_link: if path is sentinel.matched_link:
return sentinel.path return sentinel.path
return sentinel.serial_link_path return sentinel.serial_link_path
p3 = patch("os.path.realpath", side_effect=_realpath) with (
with p1 as is_dir_mock, p2 as scan_mock, p3: 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) res = usb.get_serial_by_id(sentinel.path)
assert res is sentinel.path assert res is sentinel.path
assert is_dir_mock.call_count == 1 assert is_dir_mock.call_count == 1