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

Side by Side Diff: client/site_tests/factory_LightSensor/factory_LightSensor.py

Issue 3226005: Refactory UI to grab shortcut keys, and tests to not look for triggers. (Closed) Base URL: http://git.chromium.org/git/autotest.git
Patch Set: Created 10 years, 3 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
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 6
7 # DESCRIPTION : factory test of ambient light sensor. Test that ALS reacts to 7 # DESCRIPTION : factory test of ambient light sensor. Test that ALS reacts to
8 # both darkening by covering w/ finger as well as brightening. 8 # both darkening by covering w/ finger as well as brightening.
9 # Roughly speaking: 9 # Roughly speaking:
10 # indoor ambient lighting: 20-100 10 # indoor ambient lighting: 20-100
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return self.buf[0] 101 return self.buf[0]
102 else: 102 else:
103 error.ValueError('Illegal value %s for type' % type) 103 error.ValueError('Illegal value %s for type' % type)
104 104
105 class factory_LightSensor(test.test): 105 class factory_LightSensor(test.test):
106 version = 1 106 version = 1
107 107
108 def key_release_callback(self, widget, event): 108 def key_release_callback(self, widget, event):
109 if event.keyval == ord('Q'): 109 if event.keyval == ord('Q'):
110 gtk.main_quit() 110 gtk.main_quit()
111 else:
112 self._ft_state.exit_on_trigger(event)
113 return True 111 return True
114 112
115 def timer_event(self, countdown_label): 113 def timer_event(self, countdown_label):
116 val = self._als.read('mean',samples=5, delay=0) 114 val = self._als.read('mean',samples=5, delay=0)
117 #factory.log("avg_val = %d" % val) 115 #factory.log("avg_val = %d" % val)
118 116
119 passed = 0 117 passed = 0
120 for name in _SUBTEST_LIST: 118 for name in _SUBTEST_LIST:
121 cfg = _SUBTEST_CFG[name] 119 cfg = _SUBTEST_CFG[name]
122 if 'max' in cfg: 120 if 'max' in cfg:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 hbox.pack_end(label_sep, False, False) 163 hbox.pack_end(label_sep, False, False)
166 hbox.pack_end(label_en, False, False) 164 hbox.pack_end(label_en, False, False)
167 eb.add(hbox) 165 eb.add(hbox)
168 return eb 166 return eb
169 167
170 def register_callbacks(self, window): 168 def register_callbacks(self, window):
171 window.connect('key-release-event', self.key_release_callback) 169 window.connect('key-release-event', self.key_release_callback)
172 window.add_events(gtk.gdk.KEY_RELEASE_MASK) 170 window.add_events(gtk.gdk.KEY_RELEASE_MASK)
173 171
174 def run_once(self, 172 def run_once(self,
175 test_widget_size=None,
176 trigger_set=None,
177 lux_min=None, 173 lux_min=None,
178 lux_max=None, 174 lux_max=None,
179 timeout=60, 175 timeout=60):
180 ): 176
181 factory.log('%s run_once' % self.__class__) 177 factory.log('%s run_once' % self.__class__)
182 178
183 self._test_widget_size=test_widget_size
184 self._als = tsl2563() 179 self._als = tsl2563()
185 self._deadline = time.time() + timeout 180 self._deadline = time.time() + timeout
186 181
187 self._ft_state = ful.State(trigger_set=trigger_set)
188
189 self._subtest_queue = [x for x in reversed(_SUBTEST_LIST)] 182 self._subtest_queue = [x for x in reversed(_SUBTEST_LIST)]
190 self._status_map = dict((n, ful.ACTIVE) for n in _SUBTEST_LIST) 183 self._status_map = dict((n, ful.ACTIVE) for n in _SUBTEST_LIST)
191 184
192 vbox = gtk.VBox() 185 vbox = gtk.VBox()
193 prompt_label = ful.make_label('Cover Sensor with Finger\n' + \ 186 prompt_label = ful.make_label(
194 '请遮蔽光传感器\n\n' + \ 187 'Cover Sensor with Finger\n' + '请遮蔽光传感器\n\n' +
195 'Shine flashlight at Sensor\n' + \ 188 'Shine flashlight at Sensor\n' + '请以灯光照射光传感器\n\n',
196 '请以灯光照射光传感器\n\n', fg=ful.WHITE) 189 fg=ful.WHITE)
197 vbox.pack_start(prompt_label, False, False) 190 vbox.pack_start(prompt_label, False, False)
198 191
199 for name in _SUBTEST_LIST: 192 for name in _SUBTEST_LIST:
200 label_box = self.make_subtest_label_box(name) 193 label_box = self.make_subtest_label_box(name)
201 vbox.pack_start(label_box, False, False) 194 vbox.pack_start(label_box, False, False)
202 cfg = _SUBTEST_CFG[name] 195 cfg = _SUBTEST_CFG[name]
203 # change defaults per factory setup 196 # change defaults per factory setup
204 if 'max' in cfg and lux_max is not None: 197 if 'max' in cfg and lux_max is not None:
205 cfg['max'] = lux_max 198 cfg['max'] = lux_max
206 if 'min' in cfg and lux_min is not None: 199 if 'min' in cfg and lux_min is not None:
207 cfg['min'] = lux_min 200 cfg['min'] = lux_min
208 201
209 countdown_widget, countdown_label = ful.make_countdown_widget() 202 countdown_widget, countdown_label = ful.make_countdown_widget()
210 vbox.pack_start(countdown_widget, False, False) 203 vbox.pack_start(countdown_widget, False, False)
211 gobject.timeout_add(200, self.timer_event, countdown_label) 204 gobject.timeout_add(200, self.timer_event, countdown_label)
212 205
213 self._test_widget = vbox 206 self._test_widget = vbox
214 self._ft_state.run_test_widget( 207 ful.run_test_widget(self.job, vbox,
215 test_widget=vbox,
216 test_widget_size=test_widget_size,
217 window_registration_callback=self.register_callbacks) 208 window_registration_callback=self.register_callbacks)
218 209
219 failed_set = set(name for name, status in self._status_map.items() 210 failed_set = set(name for name, status in self._status_map.items()
220 if status is not ful.PASSED) 211 if status is not ful.PASSED)
221 if failed_set: 212 if failed_set:
222 raise error.TestFail('some subtests failed (%s)' % 213 raise error.TestFail('some subtests failed (%s)' %
223 ', '.join(failed_set)) 214 ', '.join(failed_set))
224 215
225 factory.log('%s run_once finished' % self.__class__) 216 factory.log('%s run_once finished' % self.__class__)
OLDNEW
« no previous file with comments | « client/site_tests/factory_Leds/factory_Leds.py ('k') | client/site_tests/factory_Review/factory_Review.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698