Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2017 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 | |
| 5 import unittest | |
| 6 | |
| 7 from libs.meta_object import Element | |
| 8 from libs.meta_object import MetaDict | |
| 9 | |
| 10 | |
| 11 class ElementTest(unittest.TestCase): | |
| 12 """Tests ``Element`` class.""" | |
| 13 | |
| 14 def testIsElement(self): | |
| 15 """Tests that the ``IsElement`` of ``Element`` object returns True.""" | |
| 16 self.assertTrue(Element().IsElement()) | |
| 17 | |
| 18 | |
| 19 class MetaDictTest(unittest.TestCase): | |
| 20 """Tests ``MetaDict`` class.""" | |
| 21 | |
| 22 def testIsElement(self): | |
| 23 """Tests that the ``IsElement`` of ``MetaDict`` object returns True.""" | |
| 24 self.assertFalse(MetaDict({}).IsElement()) | |
| 25 | |
| 26 def testMetaDictGetAndSetItem(self): | |
| 27 """Tests "get" and "set" item behavior of ``MetaDict``.""" | |
| 28 d = {'a': 1, 'b': 2, 'c': 3} | |
| 29 meta_dict = MetaDict(d) | |
| 30 self.assertEqual(meta_dict['a'], d['a']) | |
| 31 self.assertEqual(meta_dict.get('b'), d.get('b')) | |
| 32 meta_dict['a'] = 9 | |
| 33 d['a'] = 9 | |
|
chanli
2017/01/18 22:14:24
Without line 33, what'll be the value of d['a']? I
Sharu Jiang
2017/01/19 00:00:52
This won't affect the test, since the test just wa
| |
| 34 self.assertEqual(meta_dict['a'], d['a']) | |
| 35 | |
| 36 def testMetaDictIterDict(self): | |
| 37 """Tests iterating ``MetaDict``.""" | |
| 38 d = {'a': 1, 'b': 2, 'c': 3} | |
| 39 meta_dict = MetaDict(d) | |
| 40 self.assertListEqual(list(key for key in meta_dict), list(key for key in d)) | |
| 41 self.assertListEqual(list(meta_dict.iteritems()), list(d.iteritems())) | |
| 42 self.assertListEqual(list(meta_dict.itervalues()), list(d.itervalues())) | |
| 43 self.assertListEqual(meta_dict.keys(), d.keys()) | |
| 44 self.assertListEqual(meta_dict.values(), d.values()) | |
| 45 self.assertEqual(MetaDict(d), MetaDict(d)) | |
| 46 | |
| OLD | NEW |