File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,11 @@ def test_mappingness(self):
165
165
assert_equal (keys , list (hdr_dt .names ))
166
166
for key , val in hdr .items ():
167
167
assert_array_equal (hdr [key ], val )
168
+ # verify that .get operates as destined
169
+ assert_equal (hdr .get ('nonexistent key' ), None )
170
+ assert_equal (hdr .get ('nonexistent key' , 'default' ), 'default' )
171
+ assert_equal (hdr .get (keys [0 ]), vals [0 ])
172
+ assert_equal (hdr .get (keys [0 ], 'default' ), vals [0 ])
168
173
169
174
def test_endianness_ro (self ):
170
175
# endianness is a read only property
Original file line number Diff line number Diff line change @@ -341,6 +341,10 @@ def items(self):
341
341
''' Return items from structured data'''
342
342
return zip (self .keys (), self .values ())
343
343
344
+ def get (self , k , d = None ):
345
+ ''' Return value for the key k if present or d otherwise'''
346
+ return (k in self .keys ()) and self ._structarr [k ] or d
347
+
344
348
def check_fix (self , logger = None , error_level = None ):
345
349
''' Check structured data with checks '''
346
350
if logger is None :
You can’t perform that action at this time.
0 commit comments