Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: chrome/test/functional/chromeos_battery.py

Issue 6990069: Adding PyAuto Battery test for ChromeOS (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that
4 # can be found in the LICENSE file.
5
6 import time
7 import logging
dtu 2011/05/25 04:02:55 Each section of imports should be alphabetized. Ac
scottc 2011/05/27 22:59:27 Done.
8
9 import pyauto_functional
10 import pyauto
11
12 from chromeos.power_strip import PowerStrip
13
14 class ChromeosBattery(pyauto.PyUITest):
15 """Tests ChromeOS Battery Status API.
Nirnimesh 2011/05/25 00:45:57 Mention upfront the setup assumptions for this tes
scottc 2011/05/27 22:59:27 Done.
16
17 Battery Info is a dictionary with the following keys:
Nirnimesh 2011/05/25 00:45:57 why this description? This is a repeat of the doc
scottc 2011/05/27 22:59:27 It explains why the battery status must be polled
18 'battery_is_present': bool
19 'line_power_on': bool
20 if 'battery_is_present':
21 'battery_percentage': float (0 ~ 100)
22 'battery_fully_charged': bool
23 if 'line_power_on':
24 'battery_time_to_full': int (seconds)
25 else:
26 'battery_time_to_empty': int (seconds)
27
28 If battery is still calculating the time left, then
29 'battery_time_to_full' and 'battery_time_to_empty'
30 will be absent.
31 """
32
33 _OUTLET_WITH_BATTERY = '.a4'
34
35
36 def setUp(self):
37 pyauto.PyUITest.setUp(self)
38 POWERSTRIP_IPADDR = '172.22.12.99'
Nirnimesh 2011/05/25 00:45:57 Please fetch ip address from a private file (like
Nirnimesh 2011/05/25 00:45:57 local variables should be small_letters_with_under
scottc 2011/05/27 22:59:27 Done.
scottc 2011/05/27 22:59:27 Done.
39 POWERSTRIP_USERNAME = 'admn'
stanleyw_google.com 2011/05/25 00:06:00 Username and password not necessary. Default is a
scottc 2011/05/27 22:59:27 Removed.
40 POWERSTRIP_PASSWORD = 'admn'
41 self._power_strip =
42 PowerStrip(POWERSTRIP_IPADDR, POWERSTRIP_USERNAME, POWERSTRIP_PASSWORD)
43
44
45 def tearDown(self):
46 #self._turnOn(ChromeosBattery._OUTLET_WITH_BATTERY) # Leave power on
Nirnimesh 2011/05/25 00:45:57 Remove commented out code
scottc 2011/05/27 22:59:27 Done.
47 self._turnOff(ChromeosBattery._OUTLET_WITH_BATTERY) # Leave power off
stanleyw_google.com 2011/05/25 00:06:00 You probably want to turn the device on after the
scottc 2011/05/27 22:59:27 Done.
48 pyauto.PyUITest.tearDown(self)
49
50
51 def _turnOn(self, outlet):
Nirnimesh 2011/05/25 00:45:57 This is a one-liner function. Do you really need i
scottc 2011/05/27 22:59:27 Removed.
52 """Power on specified outlet"""
53 self._power_strip.PowerOn(outlet)
54
stanleyw_google.com 2011/05/25 00:06:00 I think we can do without the _turnOn and turnOff
scottc 2011/05/27 22:59:27 Removed.
55
56 def _turnOff(self, outlet):
stanleyw_google.com 2011/05/25 00:06:00 Same as the comment for the _turnOn method.
scottc 2011/05/27 22:59:27 Removed.
57 """Power off specified outlet"""
58 self._power_strip.PowerOff(outlet)
59
60
61 def WaitUntilBatteryTimeIsCalculated(self):
Nirnimesh 2011/05/25 00:45:57 How long does this typically take?
scottc 2011/05/27 22:59:27 Sometimes right away (<2 seconds), usually about 1
62 battery_status = self.GetBatteryInfo()
63 if (battery_status['line_power_on'] == True):
Nirnimesh 2011/05/25 00:45:57 remove outer parens == True is redundant
scottc 2011/05/27 22:59:27 Done.
64 time_key = 'battery_time_to_full'
65 else:
66 time_key = 'battery_time_to_empty'
67 logging.info('Waiting for key = %s' % time_key)
68 return self.WaitUntil(lambda: self._timeIsCalculated(time_key),
stanleyw_google.com 2011/05/25 00:06:00 Instead of having _timeIsCalculated(time_key) mayb
dtu 2011/05/25 04:02:55 Instead of returning this and doing assertTrue in
scottc 2011/05/27 22:59:27 Removed. I originally put this in so the script wo
scottc 2011/05/27 22:59:27 Done.
69 timeout=60,
stanleyw_google.com 2011/05/25 00:06:00 This and the line below should line up with the wo
scottc 2011/05/27 22:59:27 Done.
70 retry_sleep=2)
71
72
73 def _timeIsCalculated(self, time_key):
74 battery_status = self.GetBatteryInfo()
75 logging.info(str(battery_status))
Nirnimesh 2011/05/25 00:45:57 remove
scottc 2011/05/27 22:59:27 Removed. I like seeing progress during a test run
76 return battery_status.has_key(time_key)
77
78
79 def testBatteryCharging(self):
80 """AC power ON to CrOS device with battery"""
stanleyw_google.com 2011/05/25 00:06:00 Period at the end.
Nirnimesh 2011/05/25 00:45:57 It's not clear from this description what this tes
scottc 2011/05/27 22:59:27 Done.
scottc 2011/05/27 22:59:27 Renamed to testBatteryChargesWhenACisOn
81 self._turnOn(self._OUTLET_WITH_BATTERY)
82 time.sleep(2)
stanleyw_google.com 2011/05/25 00:06:00 Why the sleep here? Is it necessary?
scottc 2011/05/27 22:59:27 Give PowerStrip switch time to settle.
83
84 """Get info about charging battery."""
Nirnimesh 2011/05/25 00:45:57 Is this a comment? Prefix # in that case (do not u
scottc 2011/05/27 22:59:27 Done.
85 self.assertTrue(self.WaitUntilBatteryTimeIsCalculated(),
86 'Battery charge time was not calculated')
Nirnimesh 2011/05/25 00:45:57 indent by 2 more space chars
krisr 2011/05/25 05:35:29 before the message string please use msg='the stri
scottc 2011/05/27 22:59:27 Done.
scottc 2011/05/27 22:59:27 Done.
87 battery_status = self.GetBatteryInfo()
88 self.printBatteryStatus(battery_status)
89
90 self.assertTrue(battery_status['battery_is_present'],
stanleyw_google.com 2011/05/25 00:06:00 It's probably better to use battery_status.get('ba
scottc 2011/05/27 22:59:27 Done.
91 'Battery is not present')
stanleyw_google.com 2011/05/25 00:06:00 Period after present.
krisr 2011/05/25 05:35:29 before the message string please use msg='the stri
scottc 2011/05/27 22:59:27 Done.
scottc 2011/05/27 22:59:27 Done.
92 self.assertTrue(battery_status['line_power_on'],
stanleyw_google.com 2011/05/25 00:06:00 Use battery_status.get(...).
scottc 2011/05/27 22:59:27 Done.
93 'Line power is off')
stanleyw_google.com 2011/05/25 00:06:00 Period after off.
krisr 2011/05/25 05:35:29 before the message string please use msg='the stri
scottc 2011/05/27 22:59:27 Done.
scottc 2011/05/27 22:59:27 Done.
94 self.assertTrue(battery_status['battery_time_to_full'] >= 0,
stanleyw_google.com 2011/05/25 00:06:00 Use battery_status.get(...).
scottc 2011/05/27 22:59:27 Done.
95 'Battery charge time is negative')
stanleyw_google.com 2011/05/25 00:06:00 Period after negative.
krisr 2011/05/25 05:35:29 before the message string please use msg='the stri
scottc 2011/05/27 22:59:27 Done.
scottc 2011/05/27 22:59:27 Done.
96
97
98 def testBatteryDischarging(self):
99 """AC power OFF to CrOS device with battery"""
stanleyw_google.com 2011/05/25 00:06:00 Period after battery.
scottc 2011/05/27 22:59:27 Done.
100 self._turnOff(self._OUTLET_WITH_BATTERY)
101 time.sleep(2)
stanleyw_google.com 2011/05/25 00:06:00 Why the sleep here?
scottc 2011/05/27 22:59:27 Give switch and AC power adapter time to settle.
102
103 """Get info about discharging battery."""
104 self.assertTrue(self.WaitUntilBatteryTimeIsCalculated(),
105 'Battery discharge time was not calculated')
106 battery_status = self.GetBatteryInfo()
107 self.printBatteryStatus(battery_status)
108
109 self.assertTrue(battery_status['battery_is_present'],
stanleyw_google.com 2011/05/25 00:06:00 It's probably better to use battery_status.get('ba
scottc 2011/05/27 22:59:27 Done.
110 'Battery is not present')
stanleyw_google.com 2011/05/25 00:06:00 Period after present.
scottc 2011/05/27 22:59:27 Done.
111 self.assertFalse(battery_status['line_power_on'],
stanleyw_google.com 2011/05/25 00:06:00 Use battery_status.get(...).
krisr 2011/05/25 05:35:29 before the message string please use msg='the stri
scottc 2011/05/27 22:59:27 Done.
scottc 2011/05/27 22:59:27 Done.
112 'Line power is off')
stanleyw_google.com 2011/05/25 00:06:00 Period after off.
scottc 2011/05/27 22:59:27 Done.
113 self.assertTrue(battery_status['battery_time_to_empty'] >= 0,
stanleyw_google.com 2011/05/25 00:06:01 Use battery_status.get(...).
krisr 2011/05/25 05:35:29 before the message string please use msg='the stri
scottc 2011/05/27 22:59:27 Done.
scottc 2011/05/27 22:59:27 Done.
114 'Battery discharge time is negative')
stanleyw_google.com 2011/05/25 00:06:01 Period after negative.
scottc 2011/05/27 22:59:27 Done.
115
116
krisr 2011/05/25 05:35:29 I would like a third test that: - Turns on A/C
scottc 2011/05/27 22:59:27 Added testBatteryTimesAreDifferent()
117 def printBatteryStatus(self, battery_status):
stanleyw_google.com 2011/05/25 00:06:01 We might not want to print all this. I think a si
Nirnimesh 2011/05/25 00:45:57 +1 You don't want to dump all this info. You're no
dtu 2011/05/25 04:02:55 Note that you can do this to achieve a similar out
scottc 2011/05/27 22:59:27 Done.
scottc 2011/05/27 22:59:27 Removed printing.
scottc 2011/05/27 22:59:27 Printing removed.
118 battery_is_present = battery_status['battery_is_present']
119 line_power_on = battery_status['line_power_on']
120 if (battery_is_present):
121 battery_percentage = battery_status['battery_percentage']
122 battery_fully_charged = battery_status['battery_fully_charged']
123 if (line_power_on):
124 battery_secs_to_full = battery_status['battery_time_to_full']
125 battery_secs_to_empty = 'n/a'
126 else:
127 battery_secs_to_empty = battery_status['battery_time_to_empty']
128 battery_secs_to_full = 'n/a'
129 else:
130 battery_percentage = 'n/a'
131 battery_fully_charged = 'n/a'
132
133 logging.info('')
134 logging.info('Battery Status:')
135 logging.info(' Battery present : %s' % str(battery_is_present))
136 logging.info(' Line power on : %s' % str(line_power_on))
137 logging.info(' Battery percent : %2.2f' % battery_percentage)
138 logging.info(' Battery fully charged : %s' % str(battery_fully_charged))
139 logging.info(' Time to full (seconds) : %s' % battery_secs_to_full)
140 logging.info(' Time to empty (seconds): %s' % battery_secs_to_empty)
141 logging.info('')
142
143
144 if __name__ == '__main__':
145 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698