Exemple #1
0
def test_r_dict_move_to_end():
    d = r_dict(strange_key_eq, strange_key_hash)
    d['1key'] = 'val1'
    d['2key'] = 'val2'
    d['3key'] = 'val3'
    # does not crash, we can't check that it actually moves to end on CPython
    move_to_end(d, '1key')
    move_to_end(d, '1key', last=False)
Exemple #2
0
def test_rordereddict_move_to_end():
    d = OrderedDict()
    d['key1'] = 'val1'
    d['key2'] = 'val2'
    d['key3'] = 'val3'
    move_to_end(d, 'key1')
    assert d.items() == [('key2', 'val2'), ('key3', 'val3'), ('key1', 'val1')]
    move_to_end(d, 'key1', last=False)
    assert d.items() == [('key1', 'val1'), ('key2', 'val2'), ('key3', 'val3')]
Exemple #3
0
 def func():
     d1 = OrderedDict()
     d1['key1'] = 'value1'
     d1['key2'] = 'value2'
     for i in range(20):
         objectmodel.move_to_end(d1, 'key1')
         assert d1.keys() == ['key2', 'key1']
         objectmodel.move_to_end(d1, 'key2')
         assert d1.keys() == ['key1', 'key2']
     for i in range(20):
         objectmodel.move_to_end(d1, 'key2', last=False)
         assert d1.keys() == ['key2', 'key1']
         objectmodel.move_to_end(d1, 'key1', last=False)
         assert d1.keys() == ['key1', 'key2']