Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Apr 6, 2018
1 parent c47a645 commit ff1bc0b
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/src/python/test_qgsauxiliarystorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def tmpPath():
f.close()
os.remove(f.fileName())

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


def createLayer():
Expand Down Expand Up @@ -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.