Skip to content

Commit cb63e82

Browse files
committedApr 29, 2017
Fix QgsJSONUtils test to work on macOS
Apparently, newer versions of QJsonDocument strip extra new lines when encoding some mapped values. Ignore in output from any version for now
1 parent e861f33 commit cb63e82

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
 

‎.ci/travis/macos/blacklist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ PyQgsAtlasComposition
2828
PyQgsComposerLegend
2929
PyQgsComposerMapGrid
3030
PyQgsDistanceArea
31-
PyQgsJSONUtils
3231
PyQgsPalLabelingBase
3332
PyQgsPalLabelingPlacement
3433
PyQgsPalLabelingComposer

‎tests/src/python/test_qgsjsonutils.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ def testEncodeValue(self):
116116
self.assertEqual(QgsJSONUtils.encodeValue(['a', 'b', 'c']), '["a","b","c"]')
117117
self.assertEqual(QgsJSONUtils.encodeValue(['a', 3, 'c']), '["a",3,"c"]')
118118
self.assertEqual(QgsJSONUtils.encodeValue(['a', 'c\nd']), '["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"}}')
121124

122125
def testExportAttributes(self):
123126
""" test exporting feature's attributes to JSON object """
@@ -375,7 +378,18 @@ def testJSONExporter(self):
375378
"extra3":[1,2,3]
376379
}
377380
}"""
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)
379393
exporter.setIncludeGeometry(True)
380394

381395
def testExportFeatureCrs(self):

0 commit comments

Comments
 (0)
Please sign in to comment.