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

Side by Side Diff: infra_libs/infra_types/test/infra_types_test.py

Issue 2213143002: Add infra_libs as a bootstrap dependency. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Removed the ugly import hack Created 4 years, 4 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 infra_types
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 = infra_types.freeze(d)
18 self.assertEqual(d, f)
19 self.assertIsInstance(f, infra_types.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 = infra_types.freeze(l)
35 self.assertSequenceEqual(l, f)
36 self.assertIsInstance(f, tuple)
37
38 def testSet(self):
39 s = {1, 2, infra_types.freeze({'bob': 100})}
40 f = infra_types.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 = {
48 'cat': 100,
49 'dog': 0,
50 }
51 f = infra_types.freeze(d)
52 t = infra_types.thaw(f)
53 self.assertEqual(d, f)
54 self.assertEqual(t, f)
55 self.assertEqual(d, t)
56 self.assertIsInstance(t, collections.OrderedDict)
57
58 def testOrderedDictRetainsOrder(self):
59 d = collections.OrderedDict()
60 d['cat'] = 100
61 d['dog'] = 0
62 f = infra_types.freeze(d)
63 t = infra_types.thaw(f)
64 self.assertEqual(d, f)
65 self.assertEqual(t, f)
66 self.assertEqual(d, t)
67 self.assertIsInstance(t, collections.OrderedDict)
68
69 def testList(self):
70 l = [1, 2, {'bob': 100}]
71 f = infra_types.freeze(l)
72 t = infra_types.thaw(f)
73 self.assertSequenceEqual(l, f)
74 self.assertSequenceEqual(f, t)
75 self.assertSequenceEqual(l, t)
76 self.assertIsInstance(t, list)
77
78 def testSet(self):
79 s = {1, 2, 'cat'}
80 f = infra_types.freeze(s)
81 t = infra_types.thaw(f)
82 self.assertEqual(s, f)
83 self.assertEqual(f, t)
84 self.assertEqual(t, s)
85 self.assertIsInstance(t, set)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698