<s> import json <EOL> import logging <EOL> import unittest2 <EOL> from st2client . utils import jsutil <EOL> LOG = logging . getLogger ( __name__ ) <EOL> DOC = { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : <NUM_LIT:6> <EOL> } , <EOL> '<STR_LIT>' : [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] <EOL> } <EOL> } <EOL> class TestGetValue ( unittest2 . TestCase ) : <EOL> def test_dot_notation ( self ) : <EOL> self . assertEqual ( jsutil . get_value ( DOC , '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( jsutil . get_value ( DOC , '<STR_LIT>' ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( jsutil . get_value ( DOC , '<STR_LIT>' ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( jsutil . get_value ( DOC , '<STR_LIT>' ) , { '<STR_LIT>' : <NUM_LIT:5> , '<STR_LIT>' : <NUM_LIT:6> } ) <EOL> self . assertListEqual ( jsutil . get_value ( DOC , '<STR_LIT>' ) , [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] ) <EOL> def test_dot_notation_with_val_error ( self ) : <EOL> self . assertRaises ( ValueError , jsutil . get_value , DOC , None ) <EOL> self . assertRaises ( ValueError , jsutil . get_value , DOC , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , jsutil . get_value , json . dumps ( DOC ) , '<STR_LIT>' ) <EOL> def test_dot_notation_with_key_error ( self ) : <EOL> self . assertIsNone ( jsutil . get_value ( DOC , '<STR_LIT>' ) ) <EOL> self . assertIsNone ( jsutil . get_value ( DOC , '<STR_LIT>' ) ) <EOL> self . assertIsNone ( jsutil . get_value ( DOC , '<STR_LIT>' ) ) <EOL> self . assertIsNone ( jsutil . get_value ( DOC , '<STR_LIT>' ) ) <EOL> class TestGetKeyValuePairs ( unittest2 . TestCase ) : <EOL> def test_select_kvps ( self ) : <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:3> } } ) <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:6> } } } ) <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:5> , '<STR_LIT>' : <NUM_LIT:6> } } } ) <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT>' : { '<STR_LIT>' : [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] } } ) <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:5> } } } ) <EOL> def test_select_kvps_with_val_error ( self ) : <EOL> self . assertRaises ( ValueError , jsutil . get_kvps , DOC , [ None ] ) <EOL> self . assertRaises ( ValueError , jsutil . get_kvps , DOC , [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( ValueError , jsutil . get_kvps , json . dumps ( DOC ) , [ '<STR_LIT>' ] ) <EOL> def test_select_kvps_with_key_error ( self ) : <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' ] ) , { } ) <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' ] ) , { } ) <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' ] ) , { } ) <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' ] ) , { } ) <EOL> self . assertEqual ( jsutil . get_kvps ( DOC , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:3> } } ) </s>
