#NEWLINE# def test_sortlevel( self ) : #NEWLINE# #INDENT# import random #NEWLINE# tuples = list ( self . index ) #NEWLINE# random . shuffle ( tuples ) #NEWLINE# index = MultiIndex . from_tuples ( tuples ) #NEWLINE# ( sorted_idx , _ ) = index . sortlevel ( 0 ) #NEWLINE# expected = MultiIndex . from_tuples ( sorted ( tuples ) ) #NEWLINE# self . assertTrue ( sorted_idx . equals ( expected ) ) #NEWLINE# ( sorted_idx , _ ) = index . sortlevel ( 0 , ascending = False ) #NEWLINE# self . assertTrue ( sorted_idx . equals ( expected [ : : ( - 1 ) ] ) ) #NEWLINE# ( sorted_idx , _ ) = index . sortlevel ( 1 ) #NEWLINE# by1 = sorted ( tuples , key = ( lambda x : ( x [ 1 ] , x [ 0 ] ) ) ) #NEWLINE# expected = MultiIndex . from_tuples ( by1 ) #NEWLINE# self . assertTrue ( sorted_idx . equals ( expected ) ) #NEWLINE# ( sorted_idx , _ ) = index . sortlevel ( 1 , ascending = False ) #NEWLINE# self . assertTrue ( sorted_idx . equals ( expected [ : : ( - 1 ) ] ) )