@@ -334,7 +334,6 @@ def test_recursiveLayer(self):
334
334
QgsMapLayerRegistry .instance ().removeMapLayer (l .id ())
335
335
336
336
def test_no_geometry (self ):
337
- source = QUrl .toPercentEncoding (os .path .join (self .testDataDir , "france_parts.shp" ))
338
337
df = QgsVirtualLayerDefinition ()
339
338
df .addSource ("vtab" , os .path .join (self .testDataDir , "france_parts.shp" ), "ogr" )
340
339
df .setGeometryWkbType (QgsWKBTypes .NoGeometry )
@@ -720,6 +719,24 @@ def test_qgisExpressionFunctions(self):
720
719
for f in l .getFeatures ():
721
720
self .assertEqual (f .attributes (), ['hello world' , 2016 , u'This' , u'project' ])
722
721
722
+ def test_query_with_accents (self ):
723
+ # shapefile with accents and latin1 encoding
724
+ df = QgsVirtualLayerDefinition ()
725
+ df .addSource ("vtab" , os .path .join (self .testDataDir , "france_parts.shp" ), "ogr" , "ISO-8859-1" )
726
+ df .setQuery (u"SELECT * FROM vtab WHERE TYPE_1 = 'Région'" )
727
+ vl = QgsVectorLayer (df .toString (), "testq" , "virtual" )
728
+ self .assertEqual (vl .isValid (), True )
729
+ ids = [f .id () for f in vl .getFeatures ()]
730
+ self .assertEqual (len (ids ), 4 )
731
+
732
+ # the same shapefile with a wrong encoding
733
+ df .addSource ("vtab" , os .path .join (self .testDataDir , "france_parts.shp" ), "ogr" , "UTF-8" )
734
+ df .setQuery (u"SELECT * FROM vtab WHERE TYPE_1 = 'Région'" )
735
+ vl2 = QgsVectorLayer (df .toString (), "testq" , "virtual" )
736
+ self .assertEqual (vl2 .isValid (), True )
737
+ ids = [f .id () for f in vl2 .getFeatures ()]
738
+ self .assertEqual (ids , [])
739
+
723
740
724
741
if __name__ == '__main__' :
725
742
unittest .main ()
0 commit comments