Skip to content

Commit

Permalink
update to ruff linter and asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodz committed Jan 4, 2024
1 parent 3ecbfc8 commit 97676ac
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 48 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 Pablo Diaz
Copyright (c) 2024 Repository Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 4 additions & 2 deletions pipewire_python/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ def _execute_shell_command(
# )

with subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT # Example ['ls ','l']
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, # Example ['ls ','l']
) as terminal_subprocess:
# Execute command depending or not in timeout
try:
Expand Down Expand Up @@ -246,7 +248,7 @@ def _generate_dict_interfaces(

data = line.replace("\t ", "").split(" ")
third_level = str(data[0])
if type(mydict[first_level]["params"]) != dict:
if not isinstance(mydict[first_level]["params"], dict):
mydict[first_level]["params"] = {}
mydict[first_level]["params"][third_level] = {
"spa": data[1],
Expand Down
82 changes: 48 additions & 34 deletions pipewire_python/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
class InvalidLink(ValueError):
"""Invalid link configuration."""


class FailedToLinkPorts(ValueError):
"""Failed to Link the Specified Ports."""

Expand Down Expand Up @@ -139,14 +140,18 @@ def _join_arguments(self, other: "Port", message: str) -> List[str]:

def connect(self, other: "Port") -> None:
"""Connect this channel to another channel."""
args = self._join_arguments(other=other, message="Cannot connect an {} to another {}.")
args = self._join_arguments(
other=other, message="Cannot connect an {} to another {}."
)
stdout, _ = _execute_shell_command(args)
if b"failed to link ports" in stdout:
raise FailedToLinkPorts(stdout)

def disconnect(self, other: "Port") -> None:
"""Disconnect this channel from another."""
args = self._join_arguments(other=other, message="Cannot disconnect an {} from another {}.")
args = self._join_arguments(
other=other, message="Cannot disconnect an {} from another {}."
)
args.append("--disconnect")
_ = _execute_shell_command(args)

Expand Down Expand Up @@ -480,7 +485,7 @@ def list_inputs(pair_stereo: bool = True) -> List[Union[StereoInput, Input]]:
"""
ports = []

inputs=_split_id_from_data("--input")
inputs = _split_id_from_data("--input")
if len(inputs) == 0:
return ports

Expand Down Expand Up @@ -624,26 +629,33 @@ def list_links() -> List[Link]:
port_type=PortType.OUTPUT if direction == "|<-" else PortType.INPUT,
)
if side_a_port.port_type == PortType.INPUT:
links.append(Link(
input=side_a_port,
output=side_b_port,
id=int(link_data_lines[i][0])
))
links.append(
Link(
input=side_a_port,
output=side_b_port,
id=int(link_data_lines[i][0]),
)
)
else:
links.append(Link(
input=side_b_port,
output=side_a_port,
id=int(link_data_lines[i][0])
))
links.append(
Link(
input=side_b_port,
output=side_a_port,
id=int(link_data_lines[i][0]),
)
)
i += 1
if i == num_link_lines:
break
# Determine if Next Line is Associated with this Link
if (not "|->" in link_data_lines[i][1] and
not "|<-" in link_data_lines[i][1]):
break # Continue to Next Link Group
if (
"|->" not in link_data_lines[i][1]
and "|<-" not in link_data_lines[i][1]
):
break # Continue to Next Link Group
return links


def list_link_groups() -> List[LinkGroup]:
"""
List the Groped Links Available on System.
Expand Down Expand Up @@ -691,29 +703,31 @@ def list_link_groups() -> List[LinkGroup]:
port_type=PortType.OUTPUT if direction == "|<-" else PortType.INPUT,
)
if side_a_port.port_type == PortType.INPUT:
links.append(Link(
input=side_a_port,
output=side_b_port,
id=int(link_data_lines[i][0])
))
links.append(
Link(
input=side_a_port,
output=side_b_port,
id=int(link_data_lines[i][0]),
)
)
else:
links.append(Link(
input=side_b_port,
output=side_a_port,
id=int(link_data_lines[i][0])
))
links.append(
Link(
input=side_b_port,
output=side_a_port,
id=int(link_data_lines[i][0]),
)
)
i += 1
if i == num_link_lines:
break
# Determine if Next Line is Associated with this Link
if (not "|->" in link_data_lines[i][1] and
not "|<-" in link_data_lines[i][1]):
break # Continue to Next Link Group
if (
"|->" not in link_data_lines[i][1]
and "|<-" not in link_data_lines[i][1]
):
break # Continue to Next Link Group
link_groups.append(
LinkGroup(
common_device=side_a_device,
common_name=side_a_name,
links=links
)
LinkGroup(common_device=side_a_device, common_name=side_a_name, links=links)
)
return link_groups
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ build-backend = "flit_core.buildapi"
[project]
name = "pipewire_python"
authors = [
{name = "Pablo Diaz", email = "[email protected]"},
{name = "Pablo Diaz"},
{name = "Anna Absi", email = "[email protected]"},
{name = "mrteathyme"},
{name = "Joe Stanley", email = "[email protected]"}
]
maintainers = [
{name = "Pablo Diaz", email = "[email protected]"}
{name = "Pablo Diaz"}
]
license = {file = "LICENSE"}
home-page = "https://github.com/pablodz/pipewire_python"
Expand Down
9 changes: 6 additions & 3 deletions tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


def test_interfaces():

# Client
audio_controller = Controller()
list_interfaces_client = audio_controller.get_list_interfaces(
Expand All @@ -11,7 +10,9 @@ def test_interfaces():

print(list_interfaces_client)
# check if dict
assert type(list_interfaces_client) is dict
assert isinstance(
list_interfaces_client, dict
), "list_interfaces_client should be of type dict"
# not empty dict
# empty on CI/CD
assert len(list_interfaces_client) >= 0
Expand All @@ -23,7 +24,9 @@ def test_interfaces():
)
print(list_interfaces_client)
# check if dict
assert type(list_interfaces_client) is dict
assert isinstance(
list_interfaces_client, dict
), "list_interfaces_client should be of type dict"
# not empty dict
# empty on CI/CD
assert len(list_interfaces_client) >= 0
13 changes: 9 additions & 4 deletions tests/test_links.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from pipewire_python.link import (
list_inputs, list_outputs, list_links, list_link_groups,
StereoInput, StereoOutput
list_inputs,
list_outputs,
list_links,
list_link_groups,
StereoInput,
StereoOutput,
)


def test_list():
"""Test that the lists provide some devices and that disconnecting clears them."""
inputs=list_inputs()
inputs = list_inputs()
if len(inputs) == 0:
return # No inputs, no point in testing
return # No inputs, no point in testing

assert list_inputs()
assert list_outputs()
Expand All @@ -23,6 +27,7 @@ def test_list():

assert len(list_links()) == 0


def test_connect_disconnect():
"""Test that all points quickly connect then disconnect."""
links = []
Expand Down
1 change: 1 addition & 0 deletions tests/test_playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# with open("beers.wav", 'w') as file:
# file.write(response.text)


#########################
# PLAYBACK #
#########################
Expand Down
5 changes: 3 additions & 2 deletions tests/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@


def test_interfaces():

# Client
audio_controller = Controller()
list_targets_client = audio_controller.get_list_targets()

print(list_targets_client)
# check if dict
assert type(list_targets_client) is dict
assert isinstance(
list_targets_client, dict
), "list_targets_client should be of type dict"
# not empty dict
# empty on CI/CD
assert len(list_targets_client) >= 0

0 comments on commit 97676ac

Please sign in to comment.