OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 import unittest | 4 import unittest |
5 | 5 |
6 from telemetry.core import gpu_device | 6 from telemetry.core import gpu_device |
7 | 7 |
8 | 8 |
9 class TestGPUDevice(unittest.TestCase): | 9 class TestGPUDevice(unittest.TestCase): |
| 10 |
10 def testConstruction(self): | 11 def testConstruction(self): |
11 device = gpu_device.GPUDevice(1000, 2000, 'test_vendor', 'test_device') | 12 device = gpu_device.GPUDevice(1000, 2000, 'test_vendor', 'test_device') |
12 self.assertEquals(device.vendor_id, 1000) | 13 self.assertEquals(device.vendor_id, 1000) |
13 self.assertEquals(device.device_id, 2000) | 14 self.assertEquals(device.device_id, 2000) |
14 self.assertEquals(device.vendor_string, 'test_vendor') | 15 self.assertEquals(device.vendor_string, 'test_vendor') |
15 self.assertEquals(device.device_string, 'test_device') | 16 self.assertEquals(device.device_string, 'test_device') |
16 | 17 |
17 def testFromDict(self): | 18 def testFromDict(self): |
18 dictionary = { 'vendor_id': 3000, | 19 dictionary = {'vendor_id': 3000, |
19 'device_id': 4000, | 20 'device_id': 4000, |
20 'vendor_string': 'test_vendor_2', | 21 'vendor_string': 'test_vendor_2', |
21 'device_string': 'test_device_2' } | 22 'device_string': 'test_device_2'} |
22 device = gpu_device.GPUDevice.FromDict(dictionary) | 23 device = gpu_device.GPUDevice.FromDict(dictionary) |
23 self.assertEquals(device.vendor_id, 3000) | 24 self.assertEquals(device.vendor_id, 3000) |
24 self.assertEquals(device.device_id, 4000) | 25 self.assertEquals(device.device_id, 4000) |
25 self.assertEquals(device.vendor_string, 'test_vendor_2') | 26 self.assertEquals(device.vendor_string, 'test_vendor_2') |
26 self.assertEquals(device.device_string, 'test_device_2') | 27 self.assertEquals(device.device_string, 'test_device_2') |
27 | 28 |
28 def testMissingAttrsFromDict(self): | 29 def testMissingAttrsFromDict(self): |
29 data = { | 30 data = { |
30 'vendor_id': 1, | 31 'vendor_id': 1, |
31 'device_id': 2, | 32 'device_id': 2, |
32 'vendor_string': 'a', | 33 'vendor_string': 'a', |
33 'device_string': 'b' | 34 'device_string': 'b' |
34 } | 35 } |
35 | 36 |
36 for k in data: | 37 for k in data: |
37 data_copy = data.copy() | 38 data_copy = data.copy() |
38 del data_copy[k] | 39 del data_copy[k] |
39 try: | 40 try: |
40 gpu_device.GPUDevice.FromDict(data_copy) | 41 gpu_device.GPUDevice.FromDict(data_copy) |
41 self.fail('Should raise exception if attribute "%s" is missing' % k) | 42 self.fail('Should raise exception if attribute "%s" is missing' % k) |
42 except AssertionError: | 43 except AssertionError: |
43 raise | 44 raise |
44 except: | 45 except KeyError: |
45 pass | 46 pass |
OLD | NEW |