<s> from collections import MutableMapping <EOL> import copy <EOL> from operator import itemgetter <EOL> import pickle <EOL> from random import shuffle <EOL> import sys <EOL> from test import mapping_tests <EOL> import pytest <EOL> from schematics . common import PY2 , PY3 <EOL> from schematics . datastructures import OrderedDict <EOL> class GeneralMappingTests ( mapping_tests . BasicTestMappingProtocol ) : <EOL> type2test = OrderedDict <EOL> def test_popitem ( self ) : <EOL> d = self . _empty_mapping ( ) <EOL> with pytest . raises ( KeyError ) : <EOL> d . popitem ( ) <EOL> class MyOrderedDict ( OrderedDict ) : <EOL> pass <EOL> class SubclassMappingTests ( mapping_tests . BasicTestMappingProtocol ) : <EOL> type2test = MyOrderedDict <EOL> def test_popitem ( self ) : <EOL> d = self . _empty_mapping ( ) <EOL> with pytest . raises ( KeyError ) : <EOL> d . popitem ( ) <EOL> def test_init ( ) : <EOL> with pytest . raises ( TypeError ) : <EOL> OrderedDict ( [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) ] , None ) <EOL> pairs = [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) ] <EOL> assert sorted ( OrderedDict ( dict ( pairs ) ) . items ( ) ) == pairs <EOL> assert sorted ( OrderedDict ( ** dict ( pairs ) ) . items ( ) ) == pairs <EOL> assert list ( OrderedDict ( pairs ) . items ( ) ) == pairs <EOL> assert list ( OrderedDict ( <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:9> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) ] , c = <NUM_LIT:3> , e = <NUM_LIT:5> ) . items ( ) ) == pairs <EOL> if PY2 and sys . version_info >= ( <NUM_LIT:2> , <NUM_LIT:7> , <NUM_LIT:1> ) or PY3 and sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:2> ) : <EOL> assert list ( OrderedDict ( self = <NUM_LIT> ) . items ( ) ) == [ ( '<STR_LIT>' , <NUM_LIT> ) ] <EOL> assert list ( OrderedDict ( other = <NUM_LIT> ) . items ( ) ) == [ ( '<STR_LIT>' , <NUM_LIT> ) ] <EOL> with pytest . raises ( TypeError ) : <EOL> OrderedDict ( <NUM_LIT> ) <EOL> with pytest . raises ( TypeError ) : <EOL> OrderedDict ( ( ) , ( ) ) <EOL> with pytest . raises ( TypeError ) : <EOL> OrderedDict . __init__ ( ) <EOL> d = OrderedDict ( [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT> ) , ( '<STR_LIT:e>' , <NUM_LIT> ) ] ) <EOL> d . __init__ ( [ ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] , g = <NUM_LIT:7> , d = <NUM_LIT:4> ) <EOL> assert ( list ( d . items ( ) ) == <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) , ( '<STR_LIT:g>' , <NUM_LIT:7> ) ] ) <EOL> def test_update ( ) : <EOL> with pytest . raises ( TypeError ) : <EOL> OrderedDict ( ) . update ( [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) ] , None ) <EOL> pairs = [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) ] <EOL> od = OrderedDict ( ) <EOL> od . update ( dict ( pairs ) ) <EOL> assert sorted ( od . items ( ) ) == pairs <EOL> od = OrderedDict ( ) <EOL> od . update ( ** dict ( pairs ) ) <EOL> assert sorted ( od . items ( ) ) == pairs <EOL> od = OrderedDict ( ) <EOL> od . update ( pairs ) <EOL> assert list ( od . items ( ) ) == pairs <EOL> od = OrderedDict ( ) <EOL> od . update ( [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:9> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) ] , c = <NUM_LIT:3> , e = <NUM_LIT:5> ) <EOL> assert list ( od . items ( ) ) == pairs <EOL> if PY2 and sys . version_info >= ( <NUM_LIT:2> , <NUM_LIT:7> , <NUM_LIT:1> ) or PY3 and sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:2> ) : <EOL> od = OrderedDict ( ) <EOL> od . update ( self = <NUM_LIT> ) <EOL> assert list ( od . items ( ) ) == [ ( '<STR_LIT>' , <NUM_LIT> ) ] <EOL> od = OrderedDict ( ) <EOL> od . update ( other = { } ) <EOL> assert list ( od . items ( ) ) == [ ( '<STR_LIT>' , { } ) ] <EOL> od = OrderedDict ( ) <EOL> od . update ( red = <NUM_LIT:5> , blue = <NUM_LIT:6> , other = <NUM_LIT:7> , self = <NUM_LIT:8> ) <EOL> assert sorted ( list ( od . items ( ) ) ) == [ ( '<STR_LIT>' , <NUM_LIT:6> ) , ( '<STR_LIT>' , <NUM_LIT:7> ) , ( '<STR_LIT>' , <NUM_LIT:5> ) , ( '<STR_LIT>' , <NUM_LIT:8> ) ] <EOL> d = OrderedDict ( [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT> ) , ( '<STR_LIT:e>' , <NUM_LIT> ) ] ) <EOL> d . update ( [ ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] , g = <NUM_LIT:7> , d = <NUM_LIT:4> ) <EOL> assert ( list ( d . items ( ) ) == <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) , ( '<STR_LIT:g>' , <NUM_LIT:7> ) ] ) <EOL> with pytest . raises ( TypeError ) : <EOL> OrderedDict ( ) . update ( <NUM_LIT> ) <EOL> with pytest . raises ( TypeError ) : <EOL> OrderedDict ( ) . update ( ( ) , ( ) ) <EOL> with pytest . raises ( TypeError ) : <EOL> OrderedDict . update ( ) <EOL> def test_abc ( ) : <EOL> assert isinstance ( OrderedDict ( ) , MutableMapping ) <EOL> assert issubclass ( OrderedDict , MutableMapping ) <EOL> def test_clear ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> shuffle ( pairs ) <EOL> od = OrderedDict ( pairs ) <EOL> assert len ( od ) == len ( pairs ) <EOL> od . clear ( ) <EOL> assert len ( od ) == <NUM_LIT:0> <EOL> def test_delitem ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> od = OrderedDict ( pairs ) <EOL> del od [ '<STR_LIT:a>' ] <EOL> assert '<STR_LIT:a>' not in od <EOL> with pytest . raises ( KeyError ) : <EOL> del od [ '<STR_LIT:a>' ] <EOL> assert list ( od . items ( ) ) == pairs [ : <NUM_LIT:2> ] + pairs [ <NUM_LIT:3> : ] <EOL> def test_setitem ( ) : <EOL> od = OrderedDict ( [ ( '<STR_LIT:d>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:3> ) , ( '<STR_LIT:a>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) ] ) <EOL> od [ '<STR_LIT:c>' ] = <NUM_LIT:10> <EOL> od [ '<STR_LIT:f>' ] = <NUM_LIT:20> <EOL> assert ( list ( od . items ( ) ) == <EOL> [ ( '<STR_LIT:d>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:10> ) , ( '<STR_LIT:a>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:20> ) ] ) <EOL> @ pytest . mark . parametrize ( '<STR_LIT:f>' , [ lambda x : x , reversed ] ) <EOL> def test_iterators ( f ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> shuffle ( pairs ) <EOL> od = OrderedDict ( pairs ) <EOL> assert list ( f ( od ) ) == [ t [ <NUM_LIT:0> ] for t in f ( pairs ) ] <EOL> assert list ( f ( od . keys ( ) ) ) == [ t [ <NUM_LIT:0> ] for t in f ( pairs ) ] <EOL> assert list ( f ( od . values ( ) ) ) == [ t [ <NUM_LIT:1> ] for t in f ( pairs ) ] <EOL> assert list ( f ( od . items ( ) ) ) == list ( f ( pairs ) ) <EOL> def test_popitem ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> shuffle ( pairs ) <EOL> od = OrderedDict ( pairs ) <EOL> while pairs : <EOL> assert od . popitem ( ) == pairs . pop ( ) <EOL> with pytest . raises ( KeyError ) : <EOL> od . popitem ( ) <EOL> assert len ( od ) == <NUM_LIT:0> <EOL> def test_pop ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> shuffle ( pairs ) <EOL> od = OrderedDict ( pairs ) <EOL> shuffle ( pairs ) <EOL> while pairs : <EOL> k , v = pairs . pop ( ) <EOL> assert od . pop ( k ) == v <EOL> with pytest . raises ( KeyError ) : <EOL> od . pop ( '<STR_LIT>' ) <EOL> assert len ( od ) == <NUM_LIT:0> <EOL> assert od . pop ( k , <NUM_LIT> ) == <NUM_LIT> <EOL> class Missing ( OrderedDict ) : <EOL> def __missing__ ( self , key ) : <EOL> return <NUM_LIT:0> <EOL> m = Missing ( a = <NUM_LIT:1> ) <EOL> assert m . pop ( '<STR_LIT:b>' , <NUM_LIT:5> ) == <NUM_LIT:5> <EOL> assert m . pop ( '<STR_LIT:a>' , <NUM_LIT:6> ) == <NUM_LIT:1> <EOL> assert m . pop ( '<STR_LIT:a>' , <NUM_LIT:6> ) == <NUM_LIT:6> <EOL> with pytest . raises ( KeyError ) : <EOL> m . pop ( '<STR_LIT:a>' ) <EOL> def test_equality ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> shuffle ( pairs ) <EOL> od1 = OrderedDict ( pairs ) <EOL> od2 = OrderedDict ( pairs ) <EOL> assert od1 == od2 <EOL> pairs = pairs [ <NUM_LIT:2> : ] + pairs [ : <NUM_LIT:2> ] <EOL> od2 = OrderedDict ( pairs ) <EOL> assert od1 != od2 <EOL> assert od1 == dict ( od2 ) <EOL> assert dict ( od2 ) == od1 <EOL> assert od1 != OrderedDict ( pairs [ : - <NUM_LIT:1> ] ) <EOL> def test_copying ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> od = OrderedDict ( pairs ) <EOL> def check ( dup ) : <EOL> assert dup is not od <EOL> assert dup == od <EOL> check ( od . copy ( ) ) <EOL> check ( copy . copy ( od ) ) <EOL> check ( copy . deepcopy ( od ) ) <EOL> for proto in range ( pickle . HIGHEST_PROTOCOL + <NUM_LIT:1> ) : <EOL> check ( pickle . loads ( pickle . dumps ( od , proto ) ) ) <EOL> check ( eval ( repr ( od ) ) ) <EOL> update_test = OrderedDict ( ) <EOL> update_test . update ( od ) <EOL> check ( update_test ) <EOL> check ( OrderedDict ( od ) ) <EOL> def test_yaml_linkage ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> od = OrderedDict ( pairs ) <EOL> assert all ( type ( pair ) == list for pair in od . __reduce__ ( ) [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> def test_reduce_not_too_fat ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> od = OrderedDict ( pairs ) <EOL> assert od . __reduce__ ( ) [ <NUM_LIT:2> ] is None <EOL> od . x = <NUM_LIT:10> <EOL> assert od . __reduce__ ( ) [ <NUM_LIT:2> ] is not None <EOL> @ pytest . mark . skipif ( PY2 , reason = '<STR_LIT>' ) <EOL> def test_pickle_recursive ( ) : <EOL> od = OrderedDict ( ) <EOL> od [ '<STR_LIT:x>' ] = od <EOL> rec = pickle . loads ( pickle . dumps ( od ) ) <EOL> assert list ( od . keys ( ) ) == list ( rec . keys ( ) ) <EOL> assert od is not rec <EOL> assert rec [ '<STR_LIT:x>' ] is rec <EOL> def test_repr ( ) : <EOL> od = OrderedDict ( [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] ) <EOL> assert ( repr ( od ) == <EOL> "<STR_LIT>" ) <EOL> assert eval ( repr ( od ) ) == od <EOL> assert repr ( OrderedDict ( ) ) == "<STR_LIT>" <EOL> def test_repr_recursive ( ) : <EOL> od = OrderedDict . fromkeys ( '<STR_LIT:abc>' ) <EOL> od [ '<STR_LIT:x>' ] = od <EOL> assert repr ( od ) == "<STR_LIT>" <EOL> def test_setdefault ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> shuffle ( pairs ) <EOL> od = OrderedDict ( pairs ) <EOL> pair_order = list ( od . items ( ) ) <EOL> assert od . setdefault ( '<STR_LIT:a>' , <NUM_LIT:10> ) == <NUM_LIT:3> <EOL> assert list ( od . items ( ) ) == pair_order <EOL> assert od . setdefault ( '<STR_LIT:x>' , <NUM_LIT:10> ) == <NUM_LIT:10> <EOL> assert list ( od . items ( ) ) [ - <NUM_LIT:1> ] == ( '<STR_LIT:x>' , <NUM_LIT:10> ) <EOL> class Missing ( OrderedDict ) : <EOL> def __missing__ ( self , key ) : <EOL> return <NUM_LIT:0> <EOL> assert Missing ( ) . setdefault ( <NUM_LIT:5> , <NUM_LIT:9> ) == <NUM_LIT:9> <EOL> def test_reinsert ( ) : <EOL> od = OrderedDict ( ) <EOL> od [ '<STR_LIT:a>' ] = <NUM_LIT:1> <EOL> od [ '<STR_LIT:b>' ] = <NUM_LIT:2> <EOL> del od [ '<STR_LIT:a>' ] <EOL> od [ '<STR_LIT:a>' ] = <NUM_LIT:1> <EOL> assert list ( od . items ( ) ) == [ ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:1> ) ] <EOL> def test_move_to_end ( ) : <EOL> od = OrderedDict . fromkeys ( '<STR_LIT>' ) <EOL> assert list ( od ) == list ( '<STR_LIT>' ) <EOL> od . move_to_end ( '<STR_LIT:c>' ) <EOL> assert list ( od ) == list ( '<STR_LIT>' ) <EOL> od . move_to_end ( '<STR_LIT:c>' , <NUM_LIT:0> ) <EOL> assert list ( od ) == list ( '<STR_LIT>' ) <EOL> od . move_to_end ( '<STR_LIT:c>' , <NUM_LIT:0> ) <EOL> assert list ( od ) == list ( '<STR_LIT>' ) <EOL> od . move_to_end ( '<STR_LIT:e>' ) <EOL> assert list ( od ) == list ( '<STR_LIT>' ) <EOL> with pytest . raises ( KeyError ) : <EOL> od . move_to_end ( '<STR_LIT:x>' ) <EOL> def test_override_update ( ) : <EOL> class MyOD ( OrderedDict ) : <EOL> def update ( self , * args , ** kwds ) : <EOL> raise Exception ( ) <EOL> items = [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:3> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) ] <EOL> assert list ( MyOD ( items ) . items ( ) ) == items <EOL> def test_sort ( ) : <EOL> pairs = [ ( '<STR_LIT:c>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:d>' , <NUM_LIT:4> ) , ( '<STR_LIT:e>' , <NUM_LIT:5> ) , ( '<STR_LIT:f>' , <NUM_LIT:6> ) ] <EOL> shuffled = pairs [ : ] <EOL> shuffle ( shuffled ) <EOL> od = OrderedDict ( shuffled ) <EOL> od . sort ( key = itemgetter ( <NUM_LIT:1> ) ) <EOL> assert list ( od . items ( ) ) == pairs <EOL> shuffle ( shuffled ) <EOL> od = OrderedDict ( shuffled ) <EOL> od . sort ( ) <EOL> assert list ( od . items ( ) ) == list ( sorted ( pairs ) ) <EOL> shuffle ( shuffled ) <EOL> od = OrderedDict ( shuffled ) <EOL> od . sort ( reverse = True ) <EOL> assert list ( od . items ( ) ) == list ( reversed ( sorted ( pairs ) ) ) </s>
