@@ -40,7 +40,7 @@ def tmpPath():
40
40
f .close ()
41
41
os .remove (f .fileName ())
42
42
43
- return f .fileName ()
43
+ return f .fileName (). replace ( '.' , '_' )
44
44
45
45
46
46
def createLayer ():
@@ -405,6 +405,45 @@ def testCreateProperty(self):
405
405
afIndex = vl .fields ().indexOf (afName )
406
406
self .assertEqual (index , afIndex )
407
407
408
+ def testQgdCreation (self ):
409
+ # New project
410
+ p = QgsProject ()
411
+ self .assertTrue (p .auxiliaryStorage ().isValid ())
412
+
413
+ # Save the project
414
+ path = tmpPath ()
415
+ qgs = path + '.qgs'
416
+ self .assertTrue (p .write (qgs ))
417
+ self .assertTrue (os .path .exists (qgs ))
418
+
419
+ # Auxiliary storage is empty so .qgd file should not be saved
420
+ qgd = path + '.qgd'
421
+ self .assertFalse (os .path .exists (qgd ))
422
+
423
+ # Add a vector layer and an auxiliary layer in the project
424
+ vl = createLayer ()
425
+ self .assertTrue (vl .isValid ())
426
+ p .addMapLayers ([vl ])
427
+
428
+ pkf = vl .fields ().field (vl .fields ().indexOf ('pk' ))
429
+ al = p .auxiliaryStorage ().createAuxiliaryLayer (pkf , vl )
430
+ self .assertTrue (al .isValid ())
431
+ vl .setAuxiliaryLayer (al )
432
+
433
+ # Add an auxiliary field to have a non empty auxiliary storage
434
+ pdef = QgsPropertyDefinition ('propname' , QgsPropertyDefinition .DataTypeNumeric , '' , '' , 'ut' )
435
+ self .assertTrue (al .addAuxiliaryField (pdef ))
436
+
437
+ # Save the project
438
+ newpath = tmpPath ()
439
+ qgs = newpath + '.qgs'
440
+ self .assertTrue (p .write (qgs ))
441
+ self .assertTrue (os .path .exists (qgs ))
442
+
443
+ # Auxiliary storage is NOT empty so .qgd file should be saved now
444
+ qgd = newpath + '.qgd'
445
+ self .assertTrue (os .path .exists (qgd ))
446
+
408
447
409
448
if __name__ == '__main__' :
410
449
unittest .main ()
0 commit comments