Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug when missing one item in the status and added debug info (BugFix) #1178

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions providers/base/bin/pipewire_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import subprocess
import argparse
import logging
import difflib
import time
import json
import sys
Expand Down Expand Up @@ -526,12 +527,22 @@ def compare_wpctl_status(self, status_1: str, status_2: str):
:param status_2: path to second wpctl status
"""
with open(status_1, "r") as s1, open(status_2, "r") as s2:
sorted_status_1 = self._sort_wpctl_status(s1.readlines())
sorted_status_2 = self._sort_wpctl_status(s2.readlines())
delta = set(sorted_status_2) - set(sorted_status_1)
if len(delta):
self.logger.info("".join(delta))
raise SystemExit("Status not match !!!")
status_1 = s1.readlines()
status_2 = s2.readlines()
sorted_status_1 = self._sort_wpctl_status(status_1)
sorted_status_2 = self._sort_wpctl_status(status_2)
delta = difflib.unified_diff(sorted_status_1, sorted_status_2, n=0)
diff = "".join(delta)
if diff:
self.logger.info("The first status:\n")
self.logger.info("".join(status_1))
self.logger.info("And the second status:\n")
self.logger.info("".join(status_2))
self.logger.info(
"Differ in the following lines (after sorting):"
)
self.logger.info(diff)
raise SystemExit("The two status don't match !!!")

def _args_parsing(self, args=sys.argv[1:]):
parser = argparse.ArgumentParser(
Expand Down
17 changes: 17 additions & 0 deletions providers/base/tests/test_pipewire_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,23 @@ def test_not_match(self, mock_wp_status, mock_open):
with self.assertRaises(SystemExit):
pt.compare_wpctl_status("s1", "s2")

@patch("builtins.open", read_data=[])
@patch("pipewire_utils.PipewireTest._sort_wpctl_status")
def test_missing_lines(self, mock_wp_status, mock_open):
pt = PipewireTest()
sorted_list_1 = [
"│ HD-Audio Generic HDMI / DisplayPort 1 Output [vol: 1.00]",
"│ HD-Audio Generic HDMI / DisplayPort 2 Output [vol: 0.74]",
"│ HD-Audio Generic HDMI / DisplayPort 3 Output [vol: 1.00]",
]
sorted_list_2 = [
"│ HD-Audio Generic HDMI / DisplayPort 1 Output [vol: 1.00]",
"│ HD-Audio Generic HDMI / DisplayPort 2 Output [vol: 0.74]",
]
mock_wp_status.side_effect = [sorted_list_1, sorted_list_2]
with self.assertRaises(SystemExit):
pt.compare_wpctl_status("s1", "s2")


class ArgsParsingTests(unittest.TestCase):
def test_success(self):
Expand Down
Loading