Skip to content

Commit

Permalink
Replaced open(Path, ...) with Path.open(...) (BugFix) (#1297)
Browse files Browse the repository at this point in the history
Fix: Path.open(...) instead of open(Path, ...)
  • Loading branch information
p-gentili authored Jun 19, 2024
1 parent c23b186 commit b29ac00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions providers/base/bin/bt_list_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
BTDevice = namedtuple("BTDevice", ["sysfs_name", "device_name"])


def get_node_content(path):
def get_node_content(path: Path):
"""Retrieve the content from a sysfs path.
:param path: path to the sysfs node
:type path: str or Path
:return: content of the sysfs node
:rtype: str
"""
with open(path, "r") as f:
with path.open("r") as f:
content = f.read().strip()
return content

Expand Down
8 changes: 5 additions & 3 deletions providers/base/tests/test_bt_list_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@


class BTTests(unittest.TestCase):
@patch("builtins.open", new_callable=mock_open, read_data=" test ")
@patch("pathlib.Path.open", new_callable=mock_open, read_data="test")
def test_get_node_content(self, mock_open):
content = bt_list_adapters.get_node_content(Path("test"))
self.assertEqual(content, "test")

@patch("builtins.open", new_callable=mock_open, read_data="bluetooth")
@patch("pathlib.Path.open", new_callable=mock_open, read_data="bluetooth")
def test_is_bluetooth_adapter(self, mock_open):
self.assertTrue(bt_list_adapters.is_bluetooth_adapter(Path("test")))

@patch("builtins.open", new_callable=mock_open, read_data="not bluetooth")
@patch(
"pathlib.Path.open", new_callable=mock_open, read_data="not bluetooth"
)
def test_is_not_bluetooth_adapter(self, mock_open):
self.assertFalse(bt_list_adapters.is_bluetooth_adapter(Path("test")))

Expand Down

0 comments on commit b29ac00

Please sign in to comment.