<s> import nose <EOL> from nose . tools import raises <EOL> import dpath . util <EOL> def test_merge_typesafe_and_separator ( ) : <EOL> src = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } <EOL> } <EOL> dst = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT:3>" <EOL> } <EOL> } <EOL> try : <EOL> dpath . util . merge ( dst , src , flags = ( dpath . util . MERGE_ADDITIVE | dpath . util . MERGE_TYPESAFE ) , separator = "<STR_LIT:;>" ) <EOL> except TypeError as e : <EOL> assert ( str ( e ) . endswith ( "<STR_LIT>" ) ) <EOL> return <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def test_merge_simple_int ( ) : <EOL> src = { <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } <EOL> dst = { <EOL> "<STR_LIT>" : <NUM_LIT:3> <EOL> } <EOL> dpath . util . merge ( dst , src ) <EOL> nose . tools . eq_ ( dst [ "<STR_LIT>" ] , src [ "<STR_LIT>" ] ) <EOL> def test_merge_simple_string ( ) : <EOL> src = { <EOL> "<STR_LIT:string>" : "<STR_LIT>" <EOL> } <EOL> dst = { <EOL> "<STR_LIT:string>" : "<STR_LIT>" <EOL> } <EOL> dpath . util . merge ( dst , src ) <EOL> nose . tools . eq_ ( dst [ "<STR_LIT:string>" ] , src [ "<STR_LIT:string>" ] ) <EOL> def test_merge_simple_list_additive ( ) : <EOL> src = { <EOL> "<STR_LIT:list>" : [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] <EOL> } <EOL> dst = { <EOL> "<STR_LIT:list>" : [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> } <EOL> dpath . util . merge ( dst , src , flags = dpath . util . MERGE_ADDITIVE ) <EOL> nose . tools . eq_ ( dst [ "<STR_LIT:list>" ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] ) <EOL> def test_merge_simple_list_replace ( ) : <EOL> src = { <EOL> "<STR_LIT:list>" : [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] <EOL> } <EOL> dst = { <EOL> "<STR_LIT:list>" : [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> } <EOL> dpath . util . merge ( dst , src , flags = dpath . util . MERGE_REPLACE ) <EOL> nose . tools . eq_ ( dst [ "<STR_LIT:list>" ] , [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] ) <EOL> def test_merge_simple_dict ( ) : <EOL> src = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:key>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> dst = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:key>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> dpath . util . merge ( dst , src ) <EOL> nose . tools . eq_ ( dst [ "<STR_LIT>" ] [ "<STR_LIT:key>" ] , src [ "<STR_LIT>" ] [ "<STR_LIT:key>" ] ) <EOL> def test_merge_filter ( ) : <EOL> def afilter ( x ) : <EOL> if "<STR_LIT>" not in str ( x ) : <EOL> return False <EOL> return True <EOL> src = { <EOL> "<STR_LIT:key>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> dst = { } <EOL> dpath . util . merge ( dst , src , afilter = afilter ) <EOL> assert ( "<STR_LIT>" in dst ) <EOL> assert ( "<STR_LIT:key>" not in dst ) <EOL> assert ( "<STR_LIT>" not in dst ) <EOL> @ raises ( TypeError ) <EOL> def test_merge_typesafe ( ) : <EOL> src = { <EOL> "<STR_LIT>" : { <EOL> } <EOL> } <EOL> dst = { <EOL> "<STR_LIT>" : [ <EOL> ] <EOL> } <EOL> dpath . util . merge ( dst , src , flags = dpath . util . MERGE_TYPESAFE ) </s>
