Skip to content

Commit 607dffd

Browse files
committed
basic tests for json type in gpkg
1 parent 5526975 commit 607dffd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/src/python/test_provider_ogr_gpkg.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,29 @@ def testTransaction(self):
12301230
self.assertEqual(len([f for f in vl2_external.getFeatures(QgsFeatureRequest())]), 1)
12311231
del vl2_external
12321232

1233+
def testJson(self):
1234+
tmpfile = os.path.join(self.basetestpath, 'test_json.gpkg')
1235+
testdata_path = unitTestDataPath('provider')
1236+
shutil.copy(os.path.join(unitTestDataPath('provider'), 'test_json.gpkg'), tmpfile)
1237+
1238+
vl = QgsVectorLayer('{}|layerid=0'.format(tmpfile, 'foo', 'ogr'))
1239+
self.assertTrue(vl.isValid())
1240+
1241+
fields = vl.dataProvider().fields()
1242+
self.assertEqual(fields.at(fields.indexFromName('json_content')).type(), QVariant.Map)
1243+
1244+
fi = vl.getFeatures(QgsFeatureRequest())
1245+
f = QgsFeature()
1246+
1247+
#test dict value
1248+
while fi.nextFeature(f):
1249+
fid = vl.fields().lookupField('fid')
1250+
if fid == 1:
1251+
value = vl.fields().lookupField('json_content')
1252+
self.assertIsInstance(f.attributes()[value], dict)
1253+
self.assertEqual(f.attributes()[value_idx], {'foo': 'bar'})
1254+
break
1255+
12331256

12341257
if __name__ == '__main__':
12351258
unittest.main()
144 KB
Binary file not shown.

0 commit comments

Comments
 (0)