#NEWLINE# def test_find_and_modify_with_sort( self ) : #NEWLINE# #INDENT# c = self . db . test #NEWLINE# c . drop ( ) #NEWLINE# for j in range ( 5 ) : #NEWLINE# #INDENT# c . insert ( { #NEWLINE# #INDENT# 'j' : j , #NEWLINE# 'i' : 0 , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# sort = { #NEWLINE# #INDENT# 'j' : DESCENDING , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertEqual ( 4 , c . find_and_modify ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'i' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , sort = sort ) [ 'j' ] ) #NEWLINE# sort = { #NEWLINE# #INDENT# 'j' : ASCENDING , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertEqual ( 0 , c . find_and_modify ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'i' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , sort = sort ) [ 'j' ] ) #NEWLINE# sort = [ ( 'j' , DESCENDING ) ] #NEWLINE# self . assertEqual ( 4 , c . find_and_modify ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'i' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , sort = sort ) [ 'j' ] ) #NEWLINE# sort = [ ( 'j' , ASCENDING ) ] #NEWLINE# self . assertEqual ( 0 , c . find_and_modify ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'i' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , sort = sort ) [ 'j' ] ) #NEWLINE# sort = SON ( [ ( 'j' , DESCENDING ) ] ) #NEWLINE# self . assertEqual ( 4 , c . find_and_modify ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'i' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , sort = sort ) [ 'j' ] ) #NEWLINE# sort = SON ( [ ( 'j' , ASCENDING ) ] ) #NEWLINE# self . assertEqual ( 0 , c . find_and_modify ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'i' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , sort = sort ) [ 'j' ] ) #NEWLINE# try : #NEWLINE# #INDENT# from collections import OrderedDict #NEWLINE# sort = OrderedDict ( [ ( 'j' , DESCENDING ) ] ) #NEWLINE# self . assertEqual ( 4 , c . find_and_modify ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'i' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , sort = sort ) [ 'j' ] ) #NEWLINE# sort = OrderedDict ( [ ( 'j' , ASCENDING ) ] ) #NEWLINE# self . assertEqual ( 0 , c . find_and_modify ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'i' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , sort = sort ) [ 'j' ] ) #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# sort = { #NEWLINE# #INDENT# 'j' : DESCENDING , #NEWLINE# 'foo' : DESCENDING , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertRaises ( TypeError , c . find_and_modify , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'i' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , sort = sort )