diff options
author | Raymond Hettinger <python@rcn.com> | 2010-09-06 21:26:09 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-09-06 21:26:09 (GMT) |
commit | f45abc97bfad3bc9737a8a8d95c1f4a60cd6f478 (patch) | |
tree | 7b24d9113c1d79480cde1daae9ed58199bc0e007 /Lib/test/test_collections.py | |
parent | 7b2a7710ef17e38e021f6f045b8cd7ad0e96d5e1 (diff) | |
download | cpython-f45abc97bfad3bc9737a8a8d95c1f4a60cd6f478.zip cpython-f45abc97bfad3bc9737a8a8d95c1f4a60cd6f478.tar.gz cpython-f45abc97bfad3bc9737a8a8d95c1f4a60cd6f478.tar.bz2 |
Add method to OrderedDict for repositioning keys to the ends.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 75d660d..7beb061 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -973,7 +973,19 @@ class TestOrderedDict(unittest.TestCase): od['a'] = 1 self.assertEqual(list(od.items()), [('b', 2), ('a', 1)]) - + def test_move_to_end(self): + od = OrderedDict.fromkeys('abcde') + self.assertEqual(list(od), list('abcde')) + od.move_to_end('c') + self.assertEqual(list(od), list('abdec')) + od.move_to_end('c', 0) + self.assertEqual(list(od), list('cabde')) + od.move_to_end('c', 0) + self.assertEqual(list(od), list('cabde')) + od.move_to_end('e') + self.assertEqual(list(od), list('cabde')) + with self.assertRaises(KeyError): + od.move_to_end('x') class GeneralMappingTests(mapping_tests.BasicTestMappingProtocol): type2test = OrderedDict |