From 5ee3f2f3c224fc34fb6c53ff61137304b3f05a59 Mon Sep 17 00:00:00 2001 From: ferbraher Date: Thu, 11 Apr 2024 11:06:41 +0200 Subject: [PATCH 1/2] Fixed bug when missing one item in the status and added debug info. --- providers/base/bin/pipewire_utils.py | 23 +++++++++++++++------ providers/base/tests/test_pipewire_utils.py | 17 +++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/providers/base/bin/pipewire_utils.py b/providers/base/bin/pipewire_utils.py index 39edae7e72..a4ac7c14f7 100755 --- a/providers/base/bin/pipewire_utils.py +++ b/providers/base/bin/pipewire_utils.py @@ -21,6 +21,7 @@ import subprocess import argparse import logging +import difflib import time import json import sys @@ -490,12 +491,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( diff --git a/providers/base/tests/test_pipewire_utils.py b/providers/base/tests/test_pipewire_utils.py index 93ad0da6f3..be0ff95285 100644 --- a/providers/base/tests/test_pipewire_utils.py +++ b/providers/base/tests/test_pipewire_utils.py @@ -825,6 +825,23 @@ def test_not_match(self, mock_wp_status, mock_open): 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): pt = PipewireTest() From 665a09f0e27d5a2aaa82e9c7daee23388f0b2e58 Mon Sep 17 00:00:00 2001 From: ferbraher Date: Tue, 16 Apr 2024 10:41:30 +0200 Subject: [PATCH 2/2] Formatted pipewire utils tests --- providers/base/tests/test_pipewire_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/base/tests/test_pipewire_utils.py b/providers/base/tests/test_pipewire_utils.py index 10d7d6f296..0e06b6b6aa 100644 --- a/providers/base/tests/test_pipewire_utils.py +++ b/providers/base/tests/test_pipewire_utils.py @@ -877,7 +877,6 @@ 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): @@ -895,6 +894,7 @@ def test_missing_lines(self, mock_wp_status, mock_open): with self.assertRaises(SystemExit): pt.compare_wpctl_status("s1", "s2") + class ArgsParsingTests(unittest.TestCase): def test_success(self): pt = PipewireTest()