Index: infra/libs/data_structures/test/data_structures_test.py |
diff --git a/infra/libs/data_structures/test/data_structures_test.py b/infra/libs/data_structures/test/data_structures_test.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bc3d37d56a183cdc62b0f6d7787b1d7f36b2982d |
--- /dev/null |
+++ b/infra/libs/data_structures/test/data_structures_test.py |
@@ -0,0 +1,73 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import unittest |
+import collections |
+ |
+from infra.libs import data_structures |
+ |
+ |
+class TestFreeze(unittest.TestCase): |
+ def testDict(self): |
+ d = collections.OrderedDict() |
+ d['cat'] = 100 |
+ d['dog'] = 0 |
+ |
+ f = data_structures.freeze(d) |
+ self.assertEqual(d, f) |
+ self.assertIsInstance(f, data_structures.FrozenDict) |
+ self.assertEqual( |
+ hash(f), |
+ hash((0, ('cat', 100))) ^ hash((1, ('dog', 0))) |
+ ) |
+ self.assertEqual(len(d), len(f)) |
+ |
+ # Cover equality |
+ self.assertEqual(f, f) |
+ self.assertNotEqual(f, 'dog') |
+ self.assertNotEqual(f, {'bob': 'hat'}) |
+ self.assertNotEqual(f, {'cat': 20, 'dog': 10}) |
+ |
+ def testList(self): |
+ l = [1, 2, {'bob': 100}] |
+ f = data_structures.freeze(l) |
+ self.assertSequenceEqual(l, f) |
+ self.assertIsInstance(f, tuple) |
+ |
+ def testSet(self): |
+ s = {1, 2, data_structures.freeze({'bob': 100})} |
+ f = data_structures.freeze(s) |
+ self.assertEqual(s, f) |
+ self.assertIsInstance(f, frozenset) |
+ |
+ |
+class TestThaw(unittest.TestCase): |
+ def testDict(self): |
+ d = collections.OrderedDict() |
+ d['cat'] = 100 |
+ d['dog'] = 0 |
+ f = data_structures.freeze(d) |
+ t = data_structures.thaw(f) |
+ self.assertEqual(d, f) |
+ self.assertEqual(t, f) |
+ self.assertEqual(d, t) |
+ self.assertIsInstance(t, collections.OrderedDict) |
+ |
+ def testList(self): |
+ l = [1, 2, {'bob': 100}] |
+ f = data_structures.freeze(l) |
+ t = data_structures.thaw(f) |
+ self.assertSequenceEqual(l, f) |
+ self.assertSequenceEqual(f, t) |
+ self.assertSequenceEqual(l, t) |
+ self.assertIsInstance(t, list) |
+ |
+ def testSet(self): |
+ s = {1, 2, 'cat'} |
+ f = data_structures.freeze(s) |
+ t = data_structures.thaw(f) |
+ self.assertEqual(s, f) |
+ self.assertEqual(f, t) |
+ self.assertEqual(t, s) |
+ self.assertIsInstance(t, set) |
agable
2014/06/27 18:53:11
Add TestFreezeThaw and assert that the start/end s
|