Skip to content

Commit

Permalink
Fixed bug when missing one item in the status and added debug info (B…
Browse files Browse the repository at this point in the history
…ugFix) (canonical#1178)

* Fixed bug when missing one item in the status and added debug info.

* Formatted pipewire utils tests
  • Loading branch information
fernando79513 authored and LiaoU3 committed Apr 17, 2024
1 parent d80dd75 commit 64d9493
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
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

0 comments on commit 64d9493

Please sign in to comment.