Merge lp:~pieq/checkbox/fix-1489817-audio-settings-volume-regexp into lp:checkbox

Proposed by Pierre Equoy
Status: Merged
Approved by: Po-Hsu Lin
Approved revision: 3976
Merged at revision: 3976
Proposed branch: lp:~pieq/checkbox/fix-1489817-audio-settings-volume-regexp
Merge into: lp:checkbox
Diff against target: 12 lines (+1/-1)
1 file modified
checkbox-support/checkbox_support/scripts/audio_settings.py (+1/-1)
To merge this branch: bzr merge lp:~pieq/checkbox/fix-1489817-audio-settings-volume-regexp
Reviewer Review Type Date Requested Status
Po-Hsu Lin Approve
Review via email: mp+269838@code.launchpad.net

Description of the change

audio_settings script is used to store and restore values before and after audio tests.

To do this, it uses a few regular expressions. The one to find the volume value was wrong:

    volume_regex = re.compile("Volume: (?:0|front-left):\s*([0-9])*")

Later in the code, we use group(1) to retrieve the value. However, as you can see above, group(1) will always be only one digit.

>>> vol100 = "Volume: 0: 100% 1: 100%"
>>> vol46 = "Volume: 0: 46% 1: 46%"
>>> vol4 = "Volume: 0: 4% 1: 4%"

>>> vol_regex = re.compile("Volume: (?:0|front-left):\s*([0-9])*")

>>> vol_regex.search(vol100).group(1).strip()
'0'
>>> vol_regex.search(vol46).group(1).strip()
'6'

By switching two characters in the previous regexp, everything works as expected:

    volume_regex = re.compile("Volume: (?:0|front-left):\s*([0-9]*)")
                                                                 ^

>>> vol_regex = re.compile("Volume: (?:0|front-left):\s*([0-9]*)")

>>> vol_regex.search(vol46).group(1).strip()
'46'
>>> vol_regex.search(vol100).group(1).strip()
'100'
>>> vol_regex.search(vol4).group(1).strip()
'4'

I tested the patch with `audio/playback_auto` test and the sound is restored to its previous value correctly.

To post a comment you must log in.
Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

Looking good, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox-support/checkbox_support/scripts/audio_settings.py'
2--- checkbox-support/checkbox_support/scripts/audio_settings.py 2015-06-08 17:00:38 +0000
3+++ checkbox-support/checkbox_support/scripts/audio_settings.py 2015-09-02 04:20:41 +0000
4@@ -38,7 +38,7 @@
5 default_pattern = "(?<=Default %s: ).*"
6 index_regex = re.compile("(?<=index: )[0-9]*")
7 muted_regex = re.compile("(?<=Mute: ).*")
8-volume_regex = re.compile("Volume: (?:0|front-left):\s*([0-9])*")
9+volume_regex = re.compile("Volume: (?:0|front-left):\s*([0-9]*)")
10 name_regex = re.compile("(?<=Name:).*")
11
12 entry_pattern = "Name: %s.*?(?=Properties)"

Subscribers

People subscribed via source and target branches