Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dakcarto committed Apr 29, 2017
1 parent e861f33 commit cb63e82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 0 additions & 1 deletion .ci/travis/macos/blacklist.txt
Expand Up @@ -28,7 +28,6 @@ PyQgsAtlasComposition
PyQgsComposerLegend
PyQgsComposerMapGrid
PyQgsDistanceArea
PyQgsJSONUtils
PyQgsPalLabelingBase
PyQgsPalLabelingPlacement
PyQgsPalLabelingComposer
Expand Down
20 changes: 17 additions & 3 deletions tests/src/python/test_qgsjsonutils.py
Expand Up @@ -116,8 +116,11 @@ def testEncodeValue(self):
self.assertEqual(QgsJSONUtils.encodeValue(['a', 'b', 'c']), '["a","b","c"]')
self.assertEqual(QgsJSONUtils.encodeValue(['a', 3, 'c']), '["a",3,"c"]')
self.assertEqual(QgsJSONUtils.encodeValue(['a', 'c\nd']), '["a","c\\nd"]')
self.assertEqual(QgsJSONUtils.encodeValue({'key': 'value', 'key2': 5}), '{"key":"value",\n"key2":5}')
self.assertEqual(QgsJSONUtils.encodeValue({'key': [1, 2, 3], 'key2': {'nested': 'nested\\result'}}), '{"key":[1,2,3],\n"key2":{"nested":"nested\\\\result"}}')
# handle differences due to Qt5 version, where compact output now lacks \n
enc_str = QgsJSONUtils.encodeValue({'key': 'value', 'key2': 5})
self.assertTrue(enc_str == '{"key":"value",\n"key2":5}' or enc_str == '{"key":"value","key2":5}')
enc_str = QgsJSONUtils.encodeValue({'key': [1, 2, 3], 'key2': {'nested': 'nested\\result'}})
self.assertTrue(enc_str == '{"key":[1,2,3],\n"key2":{"nested":"nested\\\\result"}}' or enc_str == '{"key":[1,2,3],"key2":{"nested":"nested\\\\result"}}')

def testExportAttributes(self):
""" test exporting feature's attributes to JSON object """
Expand Down Expand Up @@ -375,7 +378,18 @@ def testJSONExporter(self):
"extra3":[1,2,3]
}
}"""
self.assertEqual(exporter.exportFeature(feature, extraProperties={"extra": "val1", "extra2": {"nested_map": 5, "nested_map2": "val"}, "extra3": [1, 2, 3]}), expected)
expected2 = """{
"type":"Feature",
"id":5,
"geometry":null,
"properties":{
"extra":"val1",
"extra2":{"nested_map":5,"nested_map2":"val"},
"extra3":[1,2,3]
}
}"""
exp_f = exporter.exportFeature(feature, extraProperties={"extra": "val1", "extra2": {"nested_map": 5, "nested_map2": "val"}, "extra3": [1, 2, 3]})
self.assertTrue(exp_f == expected or exp_f == expected2)
exporter.setIncludeGeometry(True)

def testExportFeatureCrs(self):
Expand Down

0 comments on commit cb63e82

Please sign in to comment.