@@ -116,8 +116,11 @@ def testEncodeValue(self):
116
116
self .assertEqual (QgsJSONUtils .encodeValue (['a' , 'b' , 'c' ]), '["a","b","c"]' )
117
117
self .assertEqual (QgsJSONUtils .encodeValue (['a' , 3 , 'c' ]), '["a",3,"c"]' )
118
118
self .assertEqual (QgsJSONUtils .encodeValue (['a' , 'c\n d' ]), '["a","c\\ nd"]' )
119
- self .assertEqual (QgsJSONUtils .encodeValue ({'key' : 'value' , 'key2' : 5 }), '{"key":"value",\n "key2":5}' )
120
- self .assertEqual (QgsJSONUtils .encodeValue ({'key' : [1 , 2 , 3 ], 'key2' : {'nested' : 'nested\\ result' }}), '{"key":[1,2,3],\n "key2":{"nested":"nested\\ \\ result"}}' )
119
+ # handle differences due to Qt5 version, where compact output now lacks \n
120
+ enc_str = QgsJSONUtils .encodeValue ({'key' : 'value' , 'key2' : 5 })
121
+ self .assertTrue (enc_str == '{"key":"value",\n "key2":5}' or enc_str == '{"key":"value","key2":5}' )
122
+ enc_str = QgsJSONUtils .encodeValue ({'key' : [1 , 2 , 3 ], 'key2' : {'nested' : 'nested\\ result' }})
123
+ self .assertTrue (enc_str == '{"key":[1,2,3],\n "key2":{"nested":"nested\\ \\ result"}}' or enc_str == '{"key":[1,2,3],"key2":{"nested":"nested\\ \\ result"}}' )
121
124
122
125
def testExportAttributes (self ):
123
126
""" test exporting feature's attributes to JSON object """
@@ -375,7 +378,18 @@ def testJSONExporter(self):
375
378
"extra3":[1,2,3]
376
379
}
377
380
}"""
378
- self .assertEqual (exporter .exportFeature (feature , extraProperties = {"extra" : "val1" , "extra2" : {"nested_map" : 5 , "nested_map2" : "val" }, "extra3" : [1 , 2 , 3 ]}), expected )
381
+ expected2 = """{
382
+ "type":"Feature",
383
+ "id":5,
384
+ "geometry":null,
385
+ "properties":{
386
+ "extra":"val1",
387
+ "extra2":{"nested_map":5,"nested_map2":"val"},
388
+ "extra3":[1,2,3]
389
+ }
390
+ }"""
391
+ exp_f = exporter .exportFeature (feature , extraProperties = {"extra" : "val1" , "extra2" : {"nested_map" : 5 , "nested_map2" : "val" }, "extra3" : [1 , 2 , 3 ]})
392
+ self .assertTrue (exp_f == expected or exp_f == expected2 )
379
393
exporter .setIncludeGeometry (True )
380
394
381
395
def testExportFeatureCrs (self ):
0 commit comments