Merge lp:~roadmr/checkbox/fix-sleep-time-check-crash into lp:checkbox

Proposed by Daniel Manrique
Status: Merged
Approved by: Zygmunt Krynicki
Approved revision: 3709
Merged at revision: 3710
Proposed branch: lp:~roadmr/checkbox/fix-sleep-time-check-crash
Merge into: lp:checkbox
Diff against target: 51 lines (+16/-9)
1 file modified
providers/plainbox-provider-checkbox/bin/sleep_time_check (+16/-9)
To merge this branch: bzr merge lp:~roadmr/checkbox/fix-sleep-time-check-crash
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+256701@code.launchpad.net

Commit message

providers:checkbox: Minor fixes on sleep_time_test

Description of the change

Fixes the linked bug, some PEP8 and misc fixes.

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

+1, thanks, though it would be easier if there were separate commits for unrelated changes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'providers/plainbox-provider-checkbox/bin/sleep_time_check'
2--- providers/plainbox-provider-checkbox/bin/sleep_time_check 2014-04-11 12:25:16 +0000
3+++ providers/plainbox-provider-checkbox/bin/sleep_time_check 2015-04-17 17:58:20 +0000
4@@ -26,13 +26,16 @@
5 'resume from a sleep state. (Default: '
6 '%(default)s)'))
7 args = parser.parse_args()
8-
9+
10 try:
11- file = open(args.filename)
12- lines = file.readlines()
13- finally:
14- file.close()
15+ with open(args.filename) as file:
16+ lines = file.readlines()
17+ except IOError as e:
18+ print(e)
19+ return False
20
21+ sleep_time = None
22+ resume_time = None
23 # find our times
24 for line in lines:
25 if "Average time to sleep" in line:
26@@ -40,17 +43,21 @@
27 elif "Average time to resume" in line:
28 resume_time = float(line.split(':')[1].strip())
29
30+ if sleep_time is None or resume_time is None:
31+ print("ERROR: One or more times was not reported correctly")
32+ return False
33+
34 print("Average time to enter sleep state: %s seconds" % sleep_time)
35 print("Average time to resume from sleep state: %s seconds" % resume_time)
36-
37+
38 failed = False
39 if sleep_time > args.sleep_threshold:
40- print("System failed to suspend in less than %s seconds" %
41- args.sleep_threshold)
42+ print("System failed to suspend in less than %s seconds" %
43+ args.sleep_threshold)
44 failed = True
45 if resume_time > args.resume_threshold:
46 print("System failed to resume in less than %s seconds" %
47- args.resume_threshold)
48+ args.resume_threshold)
49 failed = True
50 if sleep_time <= 0.00 or resume_time <= 0.00:
51 print("ERROR: One or more times was not reported correctly")

Subscribers

People subscribed via source and target branches