1# Copyright (c) 2015 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. 4import unittest 5 6from tracing import value as value_module 7 8 9class ValueTests(unittest.TestCase): 10 11 def testScalar(self): 12 d = { 13 'canonical_url': '/a.json', 14 'type': 'scalar', 15 'name': 'MyScalarValue', 16 'important': False, 17 'value': {'a': 1, 'b': 'b'} 18 } 19 v = value_module.Value.FromDict(d) 20 self.assertTrue(isinstance(v, value_module.ScalarValue)) 21 d2 = v.AsDict() 22 23 self.assertEquals(d, d2) 24 25 def testDict(self): 26 d = { 27 'canonical_url': '/a.json', 28 'type': 'dict', 29 'name': 'MyDictValue', 30 'important': False, 31 'value': {'a': 1, 'b': 'b'} 32 } 33 v = value_module.Value.FromDict(d) 34 self.assertTrue(isinstance(v, value_module.DictValue)) 35 d2 = v.AsDict() 36 37 self.assertEquals(d, d2) 38 39 def testFailure(self): 40 d = { 41 'canonical_url': '/a.json', 42 'type': 'failure', 43 'name': 'Error', 44 'important': False, 45 'description': 'Some error message', 46 'stack_str': 'Some stack string' 47 } 48 v = value_module.Value.FromDict(d) 49 self.assertTrue(isinstance(v, value_module.FailureValue)) 50 d2 = v.AsDict() 51 52 self.assertEquals(d, d2) 53