<s> import pytest <EOL> import sys <EOL> import random <EOL> from . test_base_class import TestBaseClass <EOL> from aerospike import exception as e <EOL> aerospike = pytest . importorskip ( "<STR_LIT>" ) <EOL> try : <EOL> import aerospike <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> class TestListGetRange ( object ) : <EOL> @ pytest . fixture ( autouse = True ) <EOL> def setup ( self , request , as_connection ) : <EOL> keys = [ ] <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , i ) <EOL> rec = { '<STR_LIT:name>' : '<STR_LIT>' % ( str ( i ) ) , '<STR_LIT>' : [ <EOL> i , i + <NUM_LIT:1> , i + <NUM_LIT:2> , i + <NUM_LIT:3> , i + <NUM_LIT:4> , i + <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> self . as_connection . put ( key , rec ) <EOL> keys . append ( key ) <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . as_connection . list_append ( key , "<STR_LIT>" , [ <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> ] ) <EOL> keys . append ( key ) <EOL> def teardown ( ) : <EOL> """<STR_LIT>""" <EOL> for key in keys : <EOL> try : <EOL> as_connection . remove ( key ) <EOL> except e . RecordNotFound : <EOL> pass <EOL> request . addfinalizer ( teardown ) <EOL> def test_pos_list_get_range_with_correct_paramters ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> bins = self . as_connection . list_get_range ( key , "<STR_LIT>" , <NUM_LIT:4> , <NUM_LIT:3> ) <EOL> assert bins == [ <NUM_LIT:5> , <NUM_LIT:6> , [ <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> ] ] <EOL> def test_pos_list_get_range_with_correct_policy ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> policy = { <EOL> '<STR_LIT>' : <NUM_LIT:1000> , <EOL> '<STR_LIT>' : aerospike . POLICY_RETRY_ONCE , <EOL> '<STR_LIT>' : aerospike . POLICY_COMMIT_LEVEL_MASTER <EOL> } <EOL> bins = self . as_connection . list_get_range ( <EOL> key , '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:1> , { } , policy ) <EOL> assert bins == [ '<STR_LIT>' ] <EOL> def test_pos_list_get_range_with_nonexistent_bin ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> charSet = '<STR_LIT>' <EOL> minLength = <NUM_LIT:5> <EOL> maxLength = <NUM_LIT:10> <EOL> length = random . randint ( minLength , maxLength ) <EOL> bin = '<STR_LIT>' . join ( map ( lambda unused : <EOL> random . choice ( charSet ) , range ( length ) ) ) + "<STR_LIT>" <EOL> bins = self . as_connection . list_get_range ( key , bin , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> assert [ ] == bins <EOL> def test_neg_list_get_range_with_no_parameters ( self ) : <EOL> """<STR_LIT>""" <EOL> with pytest . raises ( TypeError ) as typeError : <EOL> self . as_connection . list_get_range ( ) <EOL> assert "<STR_LIT>" in str ( <EOL> typeError . value ) <EOL> def test_neg_list_get_range_with_incorrect_policy ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> policy = { <EOL> '<STR_LIT>' : <NUM_LIT:0.5> <EOL> } <EOL> try : <EOL> self . as_connection . list_get_range ( <EOL> key , "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:2> , { } , policy ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_neg_list_get_range_with_nonexistent_key ( self ) : <EOL> """<STR_LIT>""" <EOL> charSet = '<STR_LIT>' <EOL> minLength = <NUM_LIT:5> <EOL> maxLength = <NUM_LIT:30> <EOL> length = random . randint ( minLength , maxLength ) <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' . join ( map ( lambda unused : <EOL> random . choice ( charSet ) , <EOL> range ( length ) ) ) + "<STR_LIT>" ) <EOL> try : <EOL> self . as_connection . list_get_range ( key , "<STR_LIT:abc>" , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> except e . RecordNotFound as exception : <EOL> assert exception . code == <NUM_LIT:2> <EOL> def test_neg_list_get_range_with_extra_parameter ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> policy = { '<STR_LIT>' : <NUM_LIT:1000> } <EOL> with pytest . raises ( TypeError ) as typeError : <EOL> self . as_connection . list_get_range ( <EOL> key , "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT:1> , { } , policy , "<STR_LIT>" ) <EOL> assert "<STR_LIT>" in str ( <EOL> typeError . value ) <EOL> def test_neg_list_get_range_policy_is_string ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> self . as_connection . list_get_range ( <EOL> key , "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:1> , { } , "<STR_LIT>" ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_neg_list_get_range_key_is_none ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . as_connection . list_get_range ( None , "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_neg_list_get_range_bin_is_none ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> self . as_connection . list_get_range ( key , None , <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_neg_list_get_range_with_negative_index ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> self . as_connection . list_get_range ( key , "<STR_LIT>" , - <NUM_LIT> , <NUM_LIT:5> ) <EOL> except e . InvalidRequest as exception : <EOL> assert exception . code == <NUM_LIT:4> <EOL> def test_neg_list_get_range_with_negative_length ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> self . as_connection . list_get_range ( key , "<STR_LIT>" , <NUM_LIT:0> , - <NUM_LIT> ) <EOL> except e . InvalidRequest as exception : <EOL> assert exception . code == <NUM_LIT:4> <EOL> def test_neg_list_get_range_meta_type_integer ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> self . as_connection . list_get_range ( <EOL> key , "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT> ) <EOL> except e . ParamError as exception : <EOL> assert exception . code == - <NUM_LIT:2> <EOL> assert exception . msg == "<STR_LIT>" <EOL> def test_neg_list_get_range_index_type_string ( self ) : <EOL> """<STR_LIT>""" <EOL> key = ( '<STR_LIT:test>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> with pytest . raises ( TypeError ) as typeError : <EOL> self . as_connection . list_get_range ( <EOL> key , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> ) <EOL> assert "<STR_LIT>" in str ( typeError . value ) </s>
