@@ -48,11 +48,10 @@ def structured_data_api_test(self):
4848 s .Clear ()
4949 error = example .GetDescription (s )
5050 self .assertSuccess (error , "GetDescription works" )
51- # Ensure str() doesn't raise an exception.
52- self .assertTrue (str (example ))
5351 if not "key_float" in s .GetData ():
5452 self .fail ("FAILED: could not find key_float in description output" )
5553
54+ dict_struct = lldb .SBStructuredData ()
5655 dict_struct = example .GetValueForKey ("key_dict" )
5756
5857 # Tests for dictionary data type
@@ -114,26 +113,21 @@ class MyRandomClass:
114113 self .assertSuccess (example .SetFromJSON ("1" ))
115114 self .assertEqual (example .GetType (), lldb .eStructuredDataTypeInteger )
116115 self .assertEqual (example .GetIntegerValue (), 1 )
117- self .assertEqual (int (example ), 1 )
118116
119117 self .assertSuccess (example .SetFromJSON ("4.19" ))
120118 self .assertEqual (example .GetType (), lldb .eStructuredDataTypeFloat )
121119 self .assertEqual (example .GetFloatValue (), 4.19 )
122- self .assertEqual (float (example ), 4.19 )
123120
124121 self .assertSuccess (example .SetFromJSON ('"Bonjour, 123!"' ))
125122 self .assertEqual (example .GetType (), lldb .eStructuredDataTypeString )
126123 self .assertEqual (example .GetStringValue (42 ), "Bonjour, 123!" )
127- self .assertEqual (str (example ), "Bonjour, 123!" )
128124
129125 self .assertSuccess (example .SetFromJSON ("true" ))
130126 self .assertEqual (example .GetType (), lldb .eStructuredDataTypeBoolean )
131127 self .assertTrue (example .GetBooleanValue ())
132- self .assertTrue (example )
133128
134129 self .assertSuccess (example .SetFromJSON ("null" ))
135130 self .assertEqual (example .GetType (), lldb .eStructuredDataTypeNull )
136- self .assertFalse (example )
137131
138132 example = lldb .SBStructuredData ()
139133 example .SetUnsignedIntegerValue (1 )
@@ -193,35 +187,38 @@ class MyRandomClass:
193187 self .assertEqual (sb_data , example_arr )
194188
195189 def invalid_struct_test (self , example ):
190+ invalid_struct = lldb .SBStructuredData ()
196191 invalid_struct = example .GetValueForKey ("invalid_key" )
197192 if invalid_struct .IsValid ():
198193 self .fail ("An invalid object should have been returned" )
199194
200195 # Check Type API
201- if invalid_struct .GetType () ! = lldb .eStructuredDataTypeInvalid :
196+ if not invalid_struct .GetType () = = lldb .eStructuredDataTypeInvalid :
202197 self .fail ("Wrong type returned: " + str (invalid_struct .GetType ()))
203198
204199 def dictionary_struct_test (self , example ):
205200 # Check API returning a valid SBStructuredData of 'dictionary' type
201+ dict_struct = lldb .SBStructuredData ()
206202 dict_struct = example .GetValueForKey ("key_dict" )
207203 if not dict_struct .IsValid ():
208204 self .fail ("A valid object should have been returned" )
209205
210206 # Check Type API
211- if dict_struct .GetType () ! = lldb .eStructuredDataTypeDictionary :
207+ if not dict_struct .GetType () = = lldb .eStructuredDataTypeDictionary :
212208 self .fail ("Wrong type returned: " + str (dict_struct .GetType ()))
213209
214210 # Check Size API for 'dictionary' type
215- if dict_struct .GetSize () ! = 6 :
211+ if not dict_struct .GetSize () = = 6 :
216212 self .fail ("Wrong no of elements returned: " + str (dict_struct .GetSize ()))
217213
218214 def string_struct_test (self , dict_struct ):
215+ string_struct = lldb .SBStructuredData ()
219216 string_struct = dict_struct .GetValueForKey ("key_string" )
220217 if not string_struct .IsValid ():
221218 self .fail ("A valid object should have been returned" )
222219
223220 # Check Type API
224- if string_struct .GetType () ! = lldb .eStructuredDataTypeString :
221+ if not string_struct .GetType () = = lldb .eStructuredDataTypeString :
225222 self .fail ("Wrong type returned: " + str (string_struct .GetType ()))
226223
227224 # Check API returning 'string' value
@@ -241,17 +238,18 @@ def uint_struct_test(self, dict_struct):
241238 # Check a valid SBStructuredData containing an unsigned integer.
242239 # We intentionally make this larger than what an int64_t can hold but
243240 # still small enough to fit a uint64_t
241+ uint_struct = lldb .SBStructuredData ()
244242 uint_struct = dict_struct .GetValueForKey ("key_uint" )
245243 if not uint_struct .IsValid ():
246244 self .fail ("A valid object should have been returned" )
247245
248246 # Check Type API
249- if uint_struct .GetType () ! = lldb .eStructuredDataTypeInteger :
247+ if not uint_struct .GetType () = = lldb .eStructuredDataTypeInteger :
250248 self .fail ("Wrong type returned: " + str (uint_struct .GetType ()))
251249
252250 # Check API returning unsigned integer value
253251 output = uint_struct .GetUnsignedIntegerValue ()
254- if output ! = 0xFFFFFFFF00000000 :
252+ if not output = = 0xFFFFFFFF00000000 :
255253 self .fail ("wrong output: " + str (output ))
256254
257255 # Calling wrong API on a SBStructuredData
@@ -264,17 +262,18 @@ def sint_struct_test(self, dict_struct):
264262 # Check a valid SBStructuredData containing an signed integer.
265263 # We intentionally make this smaller than what an uint64_t can hold but
266264 # still small enough to fit a int64_t
265+ sint_struct = lldb .SBStructuredData ()
267266 sint_struct = dict_struct .GetValueForKey ("key_sint" )
268267 if not sint_struct .IsValid ():
269268 self .fail ("A valid object should have been returned" )
270269
271270 # Check Type API
272- if sint_struct .GetType () ! = lldb .eStructuredDataTypeSignedInteger :
271+ if not sint_struct .GetType () = = lldb .eStructuredDataTypeSignedInteger :
273272 self .fail ("Wrong type returned: " + str (sint_struct .GetType ()))
274273
275274 # Check API returning signed integer value
276275 output = sint_struct .GetSignedIntegerValue ()
277- if output ! = - 42 :
276+ if not output = = - 42 :
278277 self .fail ("wrong output: " + str (output ))
279278
280279 # Calling wrong API on a SBStructuredData
@@ -284,26 +283,28 @@ def sint_struct_test(self, dict_struct):
284283 self .fail ("Valid string " + output + " returned for an integer object" )
285284
286285 def double_struct_test (self , dict_struct ):
286+ floating_point_struct = lldb .SBStructuredData ()
287287 floating_point_struct = dict_struct .GetValueForKey ("key_float" )
288288 if not floating_point_struct .IsValid ():
289289 self .fail ("A valid object should have been returned" )
290290
291291 # Check Type API
292- if floating_point_struct .GetType () ! = lldb .eStructuredDataTypeFloat :
292+ if not floating_point_struct .GetType () = = lldb .eStructuredDataTypeFloat :
293293 self .fail ("Wrong type returned: " + str (floating_point_struct .GetType ()))
294294
295295 # Check API returning 'double' value
296296 output = floating_point_struct .GetFloatValue ()
297- if output ! = 2.99 :
297+ if not output = = 2.99 :
298298 self .fail ("wrong output: " + str (output ))
299299
300300 def bool_struct_test (self , dict_struct ):
301+ bool_struct = lldb .SBStructuredData ()
301302 bool_struct = dict_struct .GetValueForKey ("key_bool" )
302303 if not bool_struct .IsValid ():
303304 self .fail ("A valid object should have been returned" )
304305
305306 # Check Type API
306- if bool_struct .GetType () ! = lldb .eStructuredDataTypeBoolean :
307+ if not bool_struct .GetType () = = lldb .eStructuredDataTypeBoolean :
307308 self .fail ("Wrong type returned: " + str (bool_struct .GetType ()))
308309
309310 # Check API returning 'bool' value
@@ -313,108 +314,35 @@ def bool_struct_test(self, dict_struct):
313314
314315 def array_struct_test (self , dict_struct ):
315316 # Check API returning a valid SBStructuredData of 'array' type
317+ array_struct = lldb .SBStructuredData ()
316318 array_struct = dict_struct .GetValueForKey ("key_array" )
317319 if not array_struct .IsValid ():
318320 self .fail ("A valid object should have been returned" )
319321
320322 # Check Type API
321- if array_struct .GetType () ! = lldb .eStructuredDataTypeArray :
323+ if not array_struct .GetType () = = lldb .eStructuredDataTypeArray :
322324 self .fail ("Wrong type returned: " + str (array_struct .GetType ()))
323325
324326 # Check Size API for 'array' type
325- if array_struct .GetSize () ! = 2 :
327+ if not array_struct .GetSize () = = 2 :
326328 self .fail ("Wrong no of elements returned: " + str (array_struct .GetSize ()))
327329
328330 # Check API returning a valid SBStructuredData for different 'array'
329331 # indices
330332 string_struct = array_struct .GetItemAtIndex (0 )
331333 if not string_struct .IsValid ():
332334 self .fail ("A valid object should have been returned" )
333- if string_struct .GetType () ! = lldb .eStructuredDataTypeString :
335+ if not string_struct .GetType () = = lldb .eStructuredDataTypeString :
334336 self .fail ("Wrong type returned: " + str (string_struct .GetType ()))
335337 output = string_struct .GetStringValue (5 )
336- if output ! = "23" :
338+ if not output = = "23" :
337339 self .fail ("wrong output: " + str (output ))
338340
339341 string_struct = array_struct .GetItemAtIndex (1 )
340342 if not string_struct .IsValid ():
341343 self .fail ("A valid object should have been returned" )
342- if string_struct .GetType () ! = lldb .eStructuredDataTypeString :
344+ if not string_struct .GetType () = = lldb .eStructuredDataTypeString :
343345 self .fail ("Wrong type returned: " + str (string_struct .GetType ()))
344346 output = string_struct .GetStringValue (5 )
345- if output ! = "arr" :
347+ if not output = = "arr" :
346348 self .fail ("wrong output: " + str (output ))
347-
348- def test_round_trip_scalars (self ):
349- for original in (0 , 11 , - 1 , 0.0 , 4.5 , - 0.25 , True , False ):
350- constructor = type (original )
351- data = lldb .SBStructuredData ()
352- data .SetFromJSON (json .dumps (original ))
353- round_tripped = constructor (data )
354- self .assertEqual (round_tripped , original )
355-
356- def test_dynamic (self ):
357- for original in (0 , 11 , - 1 , 0.0 , 4.5 , - 0.25 , "" , "dirk" , True , False ):
358- data = lldb .SBStructuredData ()
359- data .SetFromJSON (json .dumps (original ))
360- self .assertEqual (data .dynamic , original )
361-
362- def test_round_trip_int (self ):
363- for original in (0 , 11 , - 1 ):
364- data = lldb .SBStructuredData ()
365- data .SetFromJSON (json .dumps (original ))
366- self .assertEqual (int (data ), int (original ))
367-
368- def test_round_trip_float (self ):
369- for original in (0 , 11 , - 1 , 0.0 , 4.5 , - 0.25 ):
370- data = lldb .SBStructuredData ()
371- data .SetFromJSON (json .dumps (original ))
372- self .assertEqual (float (data ), float (original ))
373-
374- def test_round_trip_bool (self ):
375- for original in (0 , 11 , - 1 , 0.0 , 4.5 , - 0.25 , "0.0" , "4.5" , "-0.25" ):
376- data = lldb .SBStructuredData ()
377- data .SetFromJSON (json .dumps (original ))
378- self .assertEqual (bool (data ), bool (original ))
379-
380- for original in ([], {}, [1 ], {1 : 1 }):
381- data = lldb .SBStructuredData ()
382- data .SetFromJSON (json .dumps (original ))
383- self .assertEqual (bool (data ), bool (original ))
384-
385- def test_assert_false (self ):
386- self .assertFalse (lldb .SBStructuredData ())
387- for original in ("0" , "0.0" , '""' , "[]" , "{}" ):
388- data = lldb .SBStructuredData ()
389- data .SetFromJSON (original )
390- self .assertFalse (data )
391-
392- def test_iterate_array (self ):
393- array = [0 , 1 , 2 ]
394- data = lldb .SBStructuredData ()
395- data .SetFromJSON (json .dumps (array ))
396- for value in data :
397- self .assertEqual (value , array .pop (0 ))
398-
399- def test_iterate_dictionary (self ):
400- dictionary = {"0" : 0 , "1" : 1 , "2" : 2 }
401- keys = set (dictionary .keys ())
402- data = lldb .SBStructuredData ()
403- data .SetFromJSON (json .dumps (dictionary ))
404- for key in data :
405- self .assertIn (key , keys )
406- keys .remove (key )
407-
408- def test_getitem_array (self ):
409- array = [1 , 2 , 3 ]
410- data = lldb .SBStructuredData ()
411- data .SetFromJSON (json .dumps (array ))
412- for i in range (len (array )):
413- self .assertEqual (data [i ], array [i ])
414-
415- def test_getitem_dictionary (self ):
416- dictionary = {"one" : 1 , "two" : 2 , "three" : 3 }
417- data = lldb .SBStructuredData ()
418- data .SetFromJSON (json .dumps (dictionary ))
419- for key in dictionary :
420- self .assertEqual (data [key ], dictionary [key ])
0 commit comments