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

Side by Side Diff: infra/libs/data_structures/test/data_structures_test.py

Issue 355153002: Refactor infra git libs and testing. (Closed) Base URL: https://chromium.googlesource.com/infra/infra@fake_testing_support
Patch Set: Created 6 years, 5 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
OLDNEW
(Empty)
1 # Copyright 2014 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 import collections
7
8 from infra.libs import data_structures
9
10
11 class TestFreeze(unittest.TestCase):
12 def testDict(self):
13 d = collections.OrderedDict()
14 d['cat'] = 100
15 d['dog'] = 0
16
17 f = data_structures.freeze(d)
18 self.assertEqual(d, f)
19 self.assertIsInstance(f, data_structures.FrozenDict)
20 self.assertEqual(
21 hash(f),
22 hash((0, ('cat', 100))) ^ hash((1, ('dog', 0)))
23 )
24 self.assertEqual(len(d), len(f))
25
26 # Cover equality
27 self.assertEqual(f, f)
28 self.assertNotEqual(f, 'dog')
29 self.assertNotEqual(f, {'bob': 'hat'})
30 self.assertNotEqual(f, {'cat': 20, 'dog': 10})
31
32 def testList(self):
33 l = [1, 2, {'bob': 100}]
34 f = data_structures.freeze(l)
35 self.assertSequenceEqual(l, f)
36 self.assertIsInstance(f, tuple)
37
38 def testSet(self):
39 s = {1, 2, data_structures.freeze({'bob': 100})}
40 f = data_structures.freeze(s)
41 self.assertEqual(s, f)
42 self.assertIsInstance(f, frozenset)
43
44
45 class TestThaw(unittest.TestCase):
46 def testDict(self):
47 d = collections.OrderedDict()
48 d['cat'] = 100
49 d['dog'] = 0
50 f = data_structures.freeze(d)
51 t = data_structures.thaw(f)
52 self.assertEqual(d, f)
53 self.assertEqual(t, f)
54 self.assertEqual(d, t)
55 self.assertIsInstance(t, collections.OrderedDict)
56
57 def testList(self):
58 l = [1, 2, {'bob': 100}]
59 f = data_structures.freeze(l)
60 t = data_structures.thaw(f)
61 self.assertSequenceEqual(l, f)
62 self.assertSequenceEqual(f, t)
63 self.assertSequenceEqual(l, t)
64 self.assertIsInstance(t, list)
65
66 def testSet(self):
67 s = {1, 2, 'cat'}
68 f = data_structures.freeze(s)
69 t = data_structures.thaw(f)
70 self.assertEqual(s, f)
71 self.assertEqual(f, t)
72 self.assertEqual(t, s)
73 self.assertIsInstance(t, set)
agable 2014/06/27 18:53:11 Add TestFreezeThaw and assert that the start/end s
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698