Skip to content
Permalink
Browse files

Add unit tests

  • Loading branch information
pblottiere committed Apr 6, 2018
1 parent c47a645 commit ff1bc0b8f7ab7946176d64abb9ab5cd72387e97e
Showing with 40 additions and 1 deletion.
  1. +40 −1 tests/src/python/test_qgsauxiliarystorage.py
@@ -40,7 +40,7 @@ def tmpPath():
f.close()
os.remove(f.fileName())

return f.fileName()
return f.fileName().replace('.', '_')


def createLayer():
@@ -405,6 +405,45 @@ def testCreateProperty(self):
afIndex = vl.fields().indexOf(afName)
self.assertEqual(index, afIndex)

def testQgdCreation(self):
# New project
p = QgsProject()
self.assertTrue(p.auxiliaryStorage().isValid())

# Save the project
path = tmpPath()
qgs = path + '.qgs'
self.assertTrue(p.write(qgs))
self.assertTrue(os.path.exists(qgs))

# Auxiliary storage is empty so .qgd file should not be saved
qgd = path + '.qgd'
self.assertFalse(os.path.exists(qgd))

# Add a vector layer and an auxiliary layer in the project
vl = createLayer()
self.assertTrue(vl.isValid())
p.addMapLayers([vl])

pkf = vl.fields().field(vl.fields().indexOf('pk'))
al = p.auxiliaryStorage().createAuxiliaryLayer(pkf, vl)
self.assertTrue(al.isValid())
vl.setAuxiliaryLayer(al)

# Add an auxiliary field to have a non empty auxiliary storage
pdef = QgsPropertyDefinition('propname', QgsPropertyDefinition.DataTypeNumeric, '', '', 'ut')
self.assertTrue(al.addAuxiliaryField(pdef))

# Save the project
newpath = tmpPath()
qgs = newpath + '.qgs'
self.assertTrue(p.write(qgs))
self.assertTrue(os.path.exists(qgs))

# Auxiliary storage is NOT empty so .qgd file should be saved now
qgd = newpath + '.qgd'
self.assertTrue(os.path.exists(qgd))


if __name__ == '__main__':
unittest.main()

0 comments on commit ff1bc0b

Please sign in to comment.
You can’t perform that action at this time.