- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / system_info_unittest.py
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
3 # found in the LICENSE file.
4 import unittest
5
6 from telemetry.core import gpu_device
7 from telemetry.core import gpu_info
8 from telemetry.core import system_info
9
10 class TestSystemInfo(unittest.TestCase):
11   def testConstruction(self):
12     data = {
13       'model_name': 'MacBookPro 10.1',
14       'gpu': {
15         'devices': [
16           { 'vendor_id': 1000, 'device_id': 2000,
17             'vendor_string': 'a', 'device_string': 'b' },
18         ]
19       }
20     }
21     info = system_info.SystemInfo.FromDict(data)
22     self.assertTrue(isinstance(info, system_info.SystemInfo))
23     self.assertTrue(isinstance(info.gpu, gpu_info.GPUInfo))
24     self.assertEquals(info.model_name, 'MacBookPro 10.1')
25     self.assertTrue(len(info.gpu.devices) == 1)
26     self.assertTrue(isinstance(info.gpu.devices[0], gpu_device.GPUDevice))
27     self.assertEquals(info.gpu.devices[0].vendor_id, 1000)
28     self.assertEquals(info.gpu.devices[0].device_id, 2000)
29     self.assertEquals(info.gpu.devices[0].vendor_string, 'a')
30     self.assertEquals(info.gpu.devices[0].device_string, 'b')
31
32   def testEmptyModelName(self):
33     data = {
34       'model_name': '',
35       'gpu': {
36         'devices': [
37           { 'vendor_id': 1000, 'device_id': 2000,
38             'vendor_string': 'a', 'device_string': 'b' },
39         ]
40       }
41     }
42     try:
43       info = system_info.SystemInfo.FromDict(data)
44       self.assertEquals(info.model_name, '')
45     except AssertionError:
46       raise
47     except:
48       self.fail('Should not raise exception for empty model_name string')
49
50   def testMissingAttrsFromDict(self):
51     data = {
52       'model_name': 'MacBookPro 10.1',
53       'devices': [{ 'vendor_id': 1000, 'device_id': 2000,
54                     'vendor_string': 'a', 'device_string': 'b' }]
55     }
56
57     for k in data:
58       data_copy = data.copy()
59       del data_copy[k]
60       try:
61         system_info.SystemInfo.FromDict(data_copy)
62         self.fail('Should raise exception if attribute "%s" is missing' % k)
63       except AssertionError:
64         raise
65       except:
66         pass