Merge ~stanley31/checkbox-support:0909_modify_audio_settings into checkbox-support:master

Proposed by StanleyHuang
Status: Merged
Approved by: Jonathan Cave
Approved revision: 319abca420c49214796fc7f4dbd5c658afa5c7b7
Merged at revision: b136d7c36518807fc15cfa8d30c98b84f9ccdfe2
Proposed branch: ~stanley31/checkbox-support:0909_modify_audio_settings
Merge into: checkbox-support:master
Diff against target: 313 lines (+87/-57)
2 files modified
checkbox_support/scripts/audio_settings.py (+82/-55)
checkbox_support/scripts/tests/test_audio_settings.py (+5/-2)
Reviewer Review Type Date Requested Status
Jonathan Cave (community) Approve
Devices Certification Bot Needs Fixing
Maciej Kisielewski Approve
Review via email: mp+408339@code.launchpad.net

Commit message

A fixed for lp:1940391

Description of the change

I have validated the audio_settings script could parse the volume from mono/stereo audio interface.

Test this script on a system with input (mono) audio and output (stereo) audio.

detail audio information:
{'name': 'bluez_source.14_3F_A6_62_7C_02.headset_head_unit', 'muted': 'no', 'volumes': {'mono': 100}, 'max_volume': 100}
{'name': 'alsa_output.pci-0000_00_1f.3.analog-stereo', 'muted': 'no', 'volumes': {'front-left': 64, 'front-right': 40}, 'max_volume': 64}

I have ran the store_audio_settings function directly, please see following contents:
default_source: bluez_source.14_3F_A6_62_7C_02.headset_head_unit
source_muted: no
source_volume: 100%
default_sink: alsa_output.pci-0000_00_1f.3.analog-stereo
sink_muted: no
sink_volume: 64%

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

I found one problem with the regex string, see below.

Nitpicking: There are at least three ways that string interpolation is used in this code (overall audio_settings.py, not just your patch):
+
.format
""%()

And I think it's pretty yucky. I'm not asking anyone to do a small revolution and fix all that, but I would prefer not to cultivate bad habits.

review: Needs Fixing
Revision history for this message
StanleyHuang (stanley31) wrote :

@Maciej,

May I have your suggestion for the way to format string?
option 1: use .format
option 2: use f"" string

If the script would only run under Python 3.6 up, I think the option 2 is a better solution due to it makes the string more readable.

Thanks.

Revision history for this message
StanleyHuang (stanley31) wrote :

I think the ".format" might be a option due to we need to replace string for some pattern variables.

Revision history for this message
StanleyHuang (stanley31) wrote :

Two commits for this MR.

first one is to change the way to parse audio volumes.
second one is to unified the format string method.

And it has been tested on my laptop with stereo and mono audio devices.
the stereo logs:
>>> print(get_audio_settings("source"))
{'name': 'alsa_input.pci-0000_00_1f.3.analog-stereo', 'muted': 'no', 'volumes': {'front-left': 26, 'front-right': 26}, 'max_volume': 26}
>>> print(get_audio_settings("sink"))
{'name': 'alsa_output.pci-0000_00_1f.3.hdmi-stereo-extra1', 'muted': 'no', 'volumes': {'front-left': 88, 'front-right': 88}, 'max_volume': 88}

the mono logs:
>>> print(get_audio_settings("source"))
{'name': 'bluez_source.74_5C_4B_D4_EB_94.headset_head_unit', 'muted': 'no', 'volumes': {'mono': 59}, 'max_volume': 59}
>>> print(get_audio_settings("sink"))
{'name': 'bluez_sink.74_5C_4B_D4_EB_94.headset_head_unit', 'muted': 'no', 'volumes': {'mono': 69}, 'max_volume': 69}

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Great stuff! Thank you for all the patches. As for which string interpolation option, I think .format() is great. One thing to note, though, is for logging calls the %s should be used, as this prevents formatting from happening unless the logging call is on the right level (it's evaluated lazily). You can read more here: https://stackoverflow.com/questions/34619790/pylint-message-logging-format-interpolation

I'm +1 on landing this.

review: Approve
Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :

The merge was fine but running tests failed.

"10.38.105.54"
"10.38.105.108"
"10.38.105.197"
[xenial] [14:06:01] starting container
Device project added to xenial-testing
"10.38.105.54"
[xenial] [14:07:16] provisioning container
[xenial] [14:09:26] Starting tests...
[xenial] Found a test script: ./requirements/container-tests-checkbox-support
[bionic] [14:09:52] starting container
Device project added to bionic-testing
[xenial] [14:10:03] container-tests-checkbox-support: FAIL
[xenial] output:
[xenial] [14:10:03] Fixing file permissions in source directory
[xenial] [14:10:04] Destroying container
[focal] [14:10:28] starting container
Device project added to focal-testing
"10.38.105.115"
[bionic] [14:10:41] provisioning container
"10.38.105.137"
[focal] [14:10:59] provisioning container
[bionic] [14:11:09] Starting tests...
[bionic] Found a test script: ./requirements/container-tests-checkbox-support
[focal] [14:11:29] Starting tests...
[focal] Found a test script: ./requirements/container-tests-checkbox-support
[bionic] [14:11:48] container-tests-checkbox-support: FAIL
[bionic] output:
[bionic] [14:11:48] Fixing file permissions in source directory
[bionic] [14:11:48] Destroying container
[focal] [14:12:03] container-tests-checkbox-support: FAIL
[focal] output:
[focal] [14:12:03] Fixing file permissions in source directory
[focal] [14:12:03] Destroying container

review: Needs Fixing
Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :

The merge was fine but running tests failed.

"10.38.105.54"
"10.38.105.108"
"10.38.105.197"
[xenial] [14:40:43] starting container
[bionic] [14:40:45] starting container
[focal] [14:40:52] starting container
Device project added to xenial-testing
Device project added to bionic-testing
"10.38.105.54"
[xenial] [14:41:02] provisioning container
Device project added to focal-testing
"10.38.105.141"
[bionic] [14:41:06] provisioning container
"10.38.105.142"
[focal] [14:41:13] provisioning container
[bionic] [14:41:44] Starting tests...
[bionic] Found a test script: ./requirements/container-tests-checkbox-support
[focal] [14:41:51] Starting tests...
[focal] Found a test script: ./requirements/container-tests-checkbox-support
[bionic] [14:42:17] container-tests-checkbox-support: FAIL
[bionic] output:
[bionic] [14:42:17] Fixing file permissions in source directory
[bionic] [14:42:18] Destroying container
[xenial] [14:42:18] Starting tests...
[xenial] Found a test script: ./requirements/container-tests-checkbox-support
[focal] [14:42:21] container-tests-checkbox-support: FAIL
[focal] output:
[focal] [14:42:21] Fixing file permissions in source directory
[focal] [14:42:22] Destroying container
[xenial] [14:42:50] container-tests-checkbox-support: FAIL
[xenial] output:
[xenial] [14:42:50] Fixing file permissions in source directory
[xenial] [14:42:50] Destroying container

review: Needs Fixing
Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :

The merge was fine but running tests failed.

"10.38.105.54"
"10.38.105.108"
"10.38.105.197"
[xenial] [17:35:38] starting container
[focal] [17:35:44] starting container
Device project added to xenial-testing
Device project added to focal-testing
"10.38.105.54"
[xenial] [17:35:56] provisioning container
"10.38.105.151"
[focal] [17:36:06] provisioning container
[bionic] [17:36:07] starting container
Device project added to bionic-testing
"10.38.105.154"
[bionic] [17:36:26] provisioning container
[focal] [17:36:38] Starting tests...
[focal] Found a test script: ./requirements/container-tests-checkbox-support
[bionic] [17:36:55] Starting tests...
[bionic] Found a test script: ./requirements/container-tests-checkbox-support
[focal] [17:37:08] container-tests-checkbox-support: FAIL
[focal] output: https://paste.ubuntu.com/p/8Mf4pRdRnj/
[focal] [17:37:11] Fixing file permissions in source directory
[focal] [17:37:11] Destroying container
[xenial] [17:37:20] Starting tests...
[xenial] Found a test script: ./requirements/container-tests-checkbox-support
[bionic] [17:37:28] container-tests-checkbox-support: FAIL
[bionic] output: https://paste.ubuntu.com/p/xDMQrgJyJN/
[bionic] [17:37:30] Fixing file permissions in source directory
[bionic] [17:37:31] Destroying container
[xenial] [17:37:52] container-tests-checkbox-support: FAIL
[xenial] output: https://paste.ubuntu.com/p/Sy353V7jcJ/
[xenial] [17:37:54] Fixing file permissions in source directory
[xenial] [17:37:54] Destroying container

review: Needs Fixing
Revision history for this message
Jonathan Cave (jocave) wrote :

@Stanley the unit tests need updating for this script. See the pastebins above for failure

review: Needs Fixing
Revision history for this message
StanleyHuang (stanley31) wrote :

attached test results of the unit test:

test_volume_regex_trusty (test_audio_settings.RegexTest)
Testing pactl 4.0 output ... ok
test_volume_regex_xenial (test_audio_settings.RegexTest)
Testing pactl 8.0 output ... ok
test_desktop_bionic_x13 (test_audio_settings.SetProfileTest)
Bionic system with a Intel UHD Graphics chipset, it's DMIC system. ... ok
test_desktop_precise_radeon_available (test_audio_settings.SetProfileTest)
Home-made system running Precise with a Radeon card. ... ok
test_desktop_precise_radeon_not_available (test_audio_settings.SetProfileTest)
Home-made system running Precise with a Radeon card. ... ok
test_desktop_precise_xps1340 (test_audio_settings.SetProfileTest)
Precise system with a Nvidia chipset. ... ok
test_desktop_raring_t430s_available (test_audio_settings.SetProfileTest)
Raring system with a Mini-DisplayPort. ... ok
test_desktop_raring_t430s_not_available (test_audio_settings.SetProfileTest)
Raring system with a Mini-DisplayPort. ... ok

----------------------------------------------------------------------
Ran 8 tests in 7.784s

OK

Revision history for this message
Jonathan Cave (jocave) wrote :

Hmmm I'm wondering why they are passing for you because I'm seeing:

======================================================================
ERROR: test_volume_regex_trusty (checkbox_support.scripts.tests.test_audio_settings.RegexTest)
Testing pactl 4.0 output
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/host/checkbox-project/checkbox-support/checkbox_support/scripts/tests/test_audio_settings.py", line 179, in test_volume_regex_trusty
    volume_regex = re.compile(volume_pattern % "0", re.DOTALL)
TypeError: not all arguments converted during string formatting

======================================================================
ERROR: test_volume_regex_xenial (checkbox_support.scripts.tests.test_audio_settings.RegexTest)
Testing pactl 8.0 output
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/host/checkbox-project/checkbox-support/checkbox_support/scripts/tests/test_audio_settings.py", line 187, in test_volume_regex_xenial
    volume_regex = re.compile(volume_pattern % "front-left", re.DOTALL)
TypeError: not all arguments converted during string formatting

Revision history for this message
StanleyHuang (stanley31) wrote :

Interesting, I guess it related to the python version.
I am going to take a look how does the audio_settings scripts works in trusty and xenial (with default python environment.

> Hmmm I'm wondering why they are passing for you because I'm seeing:
>
> ======================================================================
> ERROR: test_volume_regex_trusty
> (checkbox_support.scripts.tests.test_audio_settings.RegexTest)
> Testing pactl 4.0 output
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/home/ubuntu/host/checkbox-project/checkbox-
> support/checkbox_support/scripts/tests/test_audio_settings.py", line 179, in
> test_volume_regex_trusty
> volume_regex = re.compile(volume_pattern % "0", re.DOTALL)
> TypeError: not all arguments converted during string formatting
>
> ======================================================================
> ERROR: test_volume_regex_xenial
> (checkbox_support.scripts.tests.test_audio_settings.RegexTest)
> Testing pactl 8.0 output
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/home/ubuntu/host/checkbox-project/checkbox-
> support/checkbox_support/scripts/tests/test_audio_settings.py", line 187, in
> test_volume_regex_xenial
> volume_regex = re.compile(volume_pattern % "front-left", re.DOTALL)
> TypeError: not all arguments converted during string formatting

Revision history for this message
StanleyHuang (stanley31) wrote :

I have modified the way to format string, and run the unittest on focal and impish.
@jocave, please give it a try on your test environment. Thanks.

Revision history for this message
Jonathan Cave (jocave) wrote :

Yep, this works for me now. Attempting to land...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_support/scripts/audio_settings.py b/checkbox_support/scripts/audio_settings.py
2index 6c00743..2cf6a3f 100644
3--- a/checkbox_support/scripts/audio_settings.py
4+++ b/checkbox_support/scripts/audio_settings.py
5@@ -36,13 +36,16 @@ from checkbox_support.snap_utils.system import in_classic_snap
6 TYPES = ("source", "sink")
7 DIRECTIONS = {"source": "input", "sink": "output"}
8
9+# use %s string format to compatible with other python version
10 default_pattern = "(?<=Default %s: ).*"
11 index_regex = re.compile("(?<=Sink Input #)[0-9]*")
12 muted_regex = re.compile("(?<=Mute: ).*")
13-volume_regex = re.compile("Volume: (?:0|front-left):[\s\/0-9]*\s([0-9]*)")
14 name_regex = re.compile("(?<=Name:).*")
15+channel_map_regex = re.compile("(?<=Channel Map: ).*")
16
17+# use %s string format to compatible with other python version
18 entry_pattern = "Name: %s.*?(?=Properties)"
19+volume_pattern = r"Volume: .*(?:%s):[\w\/0-9 ]* ([0-9]*)%%"
20
21
22 def unlocalized_env(reset={"LANG": "POSIX.UTF-8"}):
23@@ -144,8 +147,8 @@ def set_profile_hdmi():
24 try:
25 check_call(["pactl", "set-card-profile", card, profile])
26 except CalledProcessError as error:
27- logging.error("Failed setting audio output to:%s: %s" %
28- (profile, error))
29+ logging.error("Failed setting audio output to:{}: {}".format(
30+ profile, error))
31
32
33 def get_current_profiles_settings(profiles_file):
34@@ -156,8 +159,8 @@ def get_current_profiles_settings(profiles_file):
35 config = configparser.ConfigParser()
36
37 for match in re.finditer(
38- "(?P<card_id>Card #\d+)\n\tName:\s+(?P<card_name>.*?)\n.*?"
39- "Active\sProfile:\s+(?P<profile>.*?)\n", pactl_list, re.M | re.S
40+ r"(?P<card_id>Card #\d+)\n\tName:\s+(?P<card_name>.*?)\n.*?"
41+ r"Active\sProfile:\s+(?P<profile>.*?)\n", pactl_list, re.M | re.S
42 ):
43 config[match.group('card_id')] = {
44 'name': match.group('card_name'),
45@@ -168,8 +171,8 @@ def get_current_profiles_settings(profiles_file):
46 with open(profiles_file, 'w') as active_profiles:
47 config.write(active_profiles)
48 except IOError:
49- logging.error("Failed to save active profiles information: %s" %
50- sys.exc_info()[1])
51+ logging.error("Failed to save active profiles information: {}".format(
52+ sys.exc_info()[1]))
53
54
55 def restore_profiles_settings(profiles_file):
56@@ -184,9 +187,9 @@ def restore_profiles_settings(profiles_file):
57 check_call(["pactl", "set-card-profile", config[card]['name'],
58 config[card]['profile']])
59 except CalledProcessError as error:
60- logging.error("Failed setting card <%s> profile to <%s>: %s" %
61- (config[card]['name'],
62- config[card]['profile'], error))
63+ logging.error(
64+ "Failed setting card <{}> profile to <{}>: {}".format(
65+ config[card]['name'], config[card]['profile'], error))
66
67
68 def move_sinks(name):
69@@ -201,49 +204,68 @@ def move_sinks(name):
70 check_call(["pactl", "move-sink-input", input_index, name],
71 stdout=DEVNULL)
72 except CalledProcessError:
73- logging.error("Failed to move input %d to sink %d" %
74- (input_index, name))
75+ logging.error("Failed to move input {} to sink {}".format(
76+ input_index, name))
77 sys.exit(1)
78
79
80+def get_audio_settings(type, name="default"):
81+ if name == "default":
82+ pactl_status = check_output(["pactl", "info"],
83+ universal_newlines=True,
84+ env=unlocalized_env())
85+ default_regex = re.compile(default_pattern % type.title())
86+ name = default_regex.search(pactl_status).group()
87+
88+ pactl_list = check_output(["pactl", "list", "{}s".format(type)],
89+ universal_newlines=True,
90+ env=unlocalized_env())
91+ entry_regex = re.compile(entry_pattern % name, re.DOTALL)
92+ entry = entry_regex.search(pactl_list).group()
93+
94+ muted = muted_regex.search(entry).group()
95+
96+ volumes = {}
97+ max_volume = 0
98+ channels = channel_map_regex.search(entry).group()
99+ for channel in channels.split(","):
100+ volume_regex = re.compile(volume_pattern % channel, re.DOTALL)
101+ _volume = int(volume_regex.search(entry).group(1).strip())
102+ volumes.update({channel: _volume})
103+ max_volume = max(_volume, max_volume)
104+
105+ return {
106+ "name": name,
107+ "muted": muted,
108+ "volumes": volumes,
109+ "max_volume": max_volume
110+ }
111+
112+
113 def store_audio_settings(file):
114 logging.info("[ Saving audio settings ]".center(80, '='))
115 try:
116 settings_file = open(file, 'w')
117 except IOError:
118- logging.error("Failed to save settings: %s" % sys.exc_info()[1])
119+ logging.error("Failed to save settings: {}".format(sys.exc_info()[1]))
120 sys.exit(1)
121
122 for type in TYPES:
123- pactl_status = check_output(["pactl", "info"],
124- universal_newlines=True,
125- env=unlocalized_env())
126- default_regex = re.compile(default_pattern % type.title())
127- default = default_regex.search(pactl_status).group()
128-
129- print("default_%s: %s" % (type, default), file=settings_file)
130-
131- pactl_list = check_output(["pactl", "list", type + 's'],
132- universal_newlines=True,
133- env=unlocalized_env())
134-
135- entry_regex = re.compile(entry_pattern % default, re.DOTALL)
136- entry = entry_regex.search(pactl_list).group()
137-
138- muted = muted_regex.search(entry)
139- print("%s_muted: %s" % (type, muted.group().strip()),
140+ audio_settings = get_audio_settings(type)
141+ print("default_{}: {}".format(type, audio_settings["name"]),
142 file=settings_file)
143-
144- volume = int(volume_regex.search(entry).group(1).strip())
145-
146- print("%s_volume: %s%%" % (type, str(volume)),
147+ print("{}_muted: {}".format(type, audio_settings["muted"].strip()),
148 file=settings_file)
149+ print("{}_volume: {}%".format(
150+ type, str(audio_settings["max_volume"])),
151+ file=settings_file)
152+
153 settings_file.close()
154
155
156 def set_audio_settings(device, mute, volume):
157 for type in TYPES:
158- pactl_entries = check_output(["pactl", "list", type + 's'],
159+ pactl_entries = check_output(["pactl", "list", "{}s".format(type)],
160 universal_newlines=True,
161 env=unlocalized_env())
162
163@@ -257,10 +279,12 @@ def set_audio_settings(device, mute, volume):
164 logging.info("[ Fallback sink ]".center(80, '='))
165 logging.info("Name: {}".format(name))
166 with open(os.devnull, 'wb') as DEVNULL:
167- check_call(["pactl", "set-default-%s" % type, name],
168+ check_call(["pactl",
169+ "set-default-{}".format(type),
170+ name],
171 stdout=DEVNULL)
172 except CalledProcessError:
173- logging.error("Failed to set default %s" % type)
174+ logging.error("Failed to set default {}".format(type))
175 sys.exit(1)
176
177 if type == "sink":
178@@ -268,16 +292,18 @@ def set_audio_settings(device, mute, volume):
179
180 try:
181 check_call(["pactl",
182- "set-%s-mute" % type, name, str(int(mute))])
183+ "set-{}-mute".format(type),
184+ name,
185+ str(int(mute))])
186 except:
187- logging.error("Failed to set mute for %s" % name)
188+ logging.error("Failed to set mute for {}".format(name))
189 sys.exit(1)
190
191 try:
192- check_call(["pactl", "set-%s-volume" % type,
193- name, str(volume) + '%'])
194+ check_call(["pactl", "set-{}-volume".format(type),
195+ name, "{}%".format(str(volume))])
196 except:
197- logging.error("Failed to set volume for %s" % name)
198+ logging.error("Failed to set volume for {}".format(name))
199 sys.exit(1)
200
201
202@@ -287,8 +313,8 @@ def restore_audio_settings(file):
203 with open(file) as f:
204 settings_file = f.read().split()
205 except IOError:
206- logging.error("Unable to open existing settings file: %s" %
207- sys.exc_info()[1])
208+ logging.error("Unable to open existing settings file: {}".format(
209+ sys.exc_info()[1]))
210 return 1
211
212 for type in TYPES:
213@@ -297,10 +323,11 @@ def restore_audio_settings(file):
214 # is incorrect, so we just abort.
215 try:
216 name = settings_file[
217- settings_file.index("default_%s:" % type) + 1]
218- muted = settings_file[settings_file.index("%s_muted:" % type) + 1]
219+ settings_file.index("default_{}:".format(type)) + 1]
220+ muted = settings_file[
221+ settings_file.index("{}_muted:".format(type)) + 1]
222 volume = settings_file[
223- settings_file.index("%s_volume:" % type) + 1]
224+ settings_file.index("{}_volume:".format(type)) + 1]
225 except ValueError:
226 logging.error("Unable to restore settings because settings "
227 "file is invalid")
228@@ -308,25 +335,25 @@ def restore_audio_settings(file):
229
230 try:
231 with open(os.devnull, 'wb') as DEVNULL:
232- check_call(["pactl", "set-default-%s" % type, name],
233+ check_call(["pactl", "set-default-{}".format(type), name],
234 stdout=DEVNULL)
235 except CalledProcessError:
236- logging.error("Failed to restore default %s" % name)
237+ logging.error("Failed to restore default {}".format(name))
238 return 1
239
240 if type == "sink":
241 move_sinks(name)
242
243 try:
244- check_call(["pactl", "set-%s-mute" % type, name, muted])
245+ check_call(["pactl", "set-{}-mute".format(type), name, muted])
246 except:
247- logging.error("Failed to restore mute for %s" % name)
248+ logging.error("Failed to restore mute for {}".format(name))
249 return 1
250
251 try:
252- check_call(["pactl", "set-%s-volume" % type, name, volume])
253+ check_call(["pactl", "set-{}-volume".format(type), name, volume])
254 except:
255- logging.error("Failed to restore volume for %s" % name)
256+ logging.error("Failed to restore volume for {}".format(name))
257 return 1
258
259
260@@ -359,7 +386,7 @@ def main():
261 logging.error("No file specified to store audio settings!")
262 return 1
263 settings_file = args.file
264- profiles_file = args.file + ".profiles"
265+ profiles_file = "{}.profiles".format(args.file)
266
267 if args.verbose:
268 logging.basicConfig(format='%(levelname)s:%(message)s',
269@@ -383,7 +410,7 @@ def main():
270 set_profile_hdmi()
271 set_audio_settings(args.device, args.mute, args.volume)
272 else:
273- logging.error(args.action + "is not a valid action")
274+ logging.error("{} is not a valid action".format(args.action))
275 return 1
276
277 return 0
278diff --git a/checkbox_support/scripts/tests/test_audio_settings.py b/checkbox_support/scripts/tests/test_audio_settings.py
279index 9f81f97..6a6b0ba 100644
280--- a/checkbox_support/scripts/tests/test_audio_settings.py
281+++ b/checkbox_support/scripts/tests/test_audio_settings.py
282@@ -22,9 +22,10 @@ from __future__ import print_function
283 from __future__ import unicode_literals
284
285 import os
286+import re
287 import unittest
288
289-from checkbox_support.scripts.audio_settings import _guess_hdmi_profile, volume_regex
290+from checkbox_support.scripts.audio_settings import _guess_hdmi_profile, volume_pattern
291 from checkbox_support.parsers.tests.test_pactl import PactlDataMixIn
292
293
294@@ -171,10 +172,11 @@ class SetProfileTest(unittest.TestCase, PactlDataMixIn):
295 ('0', 'Hdmi2'))
296
297 class RegexTest(unittest.TestCase):
298-
299+
300 def test_volume_regex_trusty(self):
301 """Testing pactl 4.0 output"""
302 pactl_volume = " Volume: 0: 47% 1: 47%"
303+ volume_regex = re.compile(volume_pattern % "0", re.DOTALL)
304 volume = int(volume_regex.search(pactl_volume).group(1).strip())
305 self.assertEqual(volume, 47)
306
307@@ -182,5 +184,6 @@ class RegexTest(unittest.TestCase):
308 """Testing pactl 8.0 output"""
309 # See lp:1595380 for more info
310 pactl_volume = " Volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB"
311+ volume_regex = re.compile(volume_pattern % "front-left", re.DOTALL)
312 volume = int(volume_regex.search(pactl_volume).group(1).strip())
313 self.assertEqual(volume, 100)

Subscribers

People subscribed via source and target branches