Skip to content
Permalink
Browse files

fix virtuallayer tests on windows

  • Loading branch information
jef-n committed Jan 6, 2016
1 parent 8c902b9 commit f5b615acdd49fe76d4d976395b04227342e26794
@@ -31,7 +31,7 @@ QgsVirtualLayerDefinition QgsVirtualLayerDefinition::fromUrl( const QUrl& url )
{
QgsVirtualLayerDefinition def;

def.setFilePath( url.path() );
def.setFilePath( url.toLocalFile() );

// regexp for column name
const QString columnNameRx( "[a-zA-Z_\x80-\xFF][a-zA-Z0-9_\x80-\xFF]*" );
@@ -74,6 +74,8 @@ QgsVirtualLayerDefinition QgsVirtualLayerDefinition::fromUrl( const QUrl& url )

providerKey = value.left( pos );
int pos2 = value.indexOf( ':', pos + 1 );
if ( pos2 - pos == 2 )
pos2 = value.indexOf( ':', pos + 3 );
if ( pos2 != -1 )
{
source = QUrl::fromPercentEncoding( value.mid( pos + 1, pos2 - pos - 1 ).toUtf8() );
@@ -19,6 +19,7 @@ email : hugo dot mercier at oslandia dot com
#include <stdexcept>

#include "qgsvirtuallayersqlitehelper.h"
#include "qgslogger.h"

QgsScopedSqlite::QgsScopedSqlite( const QString& path, bool withExtension )
{
@@ -38,7 +39,9 @@ QgsScopedSqlite::QgsScopedSqlite( const QString& path, bool withExtension )

if ( r )
{
throw std::runtime_error( sqlite3_errmsg( db_ ) );
QString err = QString( "%1 [%2]" ).arg( sqlite3_errmsg( db_ ), path );
QgsDebugMsg( err );
throw std::runtime_error( err.toLocal8Bit().constData() );
}
// enable extended result codes
sqlite3_extended_result_codes( db_, 1 );
@@ -85,7 +85,7 @@ def tearDown(self):
pass

def test_CsvNoGeometry(self):
l1 = QgsVectorLayer("file:///" + os.path.join(self.testDataDir, "delimitedtext/test.csv").replace("\\", "/") + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
self.assertEqual(l1.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l1)

@@ -96,7 +96,7 @@ def test_CsvNoGeometry(self):

def test_source_escaping(self):
# the source contains ':'
source = "file:///" + os.path.join(self.testDataDir, "delimitedtext/test.csv").replace("\\", "/") + "?type=csv&geomType=none&subsetIndex=no&watchFile=no"
source = QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no"
d = QgsVirtualLayerDefinition()
d.addSource("t", source, "delimitedtext")
l = QgsVectorLayer(d.toString(), "vtab", "virtual", False)
@@ -135,7 +135,7 @@ def create_test_db(dbfile):
self.assertEqual(l.isValid(), True)

def test_DynamicGeometry(self):
l1 = QgsVectorLayer("file:///" + os.path.join(self.testDataDir, "delimitedtext/testextpt.txt").replace("\\", "/") + "?type=csv&delimiter=%7C&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/testextpt.txt")).toString() + "?type=csv&delimiter=%7C&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
self.assertEqual(l1.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l1)

@@ -337,7 +337,7 @@ def test_no_geometry(self):

def test_reopen(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
tmp = os.path.join(tempfile.gettempdir(), "t.sqlite")
tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString()
l = QgsVectorLayer("%s?layer=ogr:%s:vtab" % (tmp, source), "vtab2", "virtual", False)
self.assertEqual(l.isValid(), True)

@@ -348,7 +348,7 @@ def test_reopen(self):

def test_reopen2(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
tmp = os.path.join(tempfile.gettempdir(), "t.sqlite")
tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString()
l = QgsVectorLayer("%s?layer=ogr:%s:vtab&nogeometry" % (tmp, source), "vtab2", "virtual", False)
self.assertEqual(l.isValid(), True)

@@ -359,7 +359,7 @@ def test_reopen2(self):

def test_reopen3(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
tmp = os.path.join(tempfile.gettempdir(), "t.sqlite")
tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString()
query = QUrl.toPercentEncoding("SELECT * FROM vtab")
l = QgsVectorLayer("%s?layer=ogr:%s:vtab&query=%s&uid=objectid&geometry=geometry:3:4326" % (tmp, source, query), "vtab2", "virtual", False)
self.assertEqual(l.isValid(), True)
@@ -375,7 +375,7 @@ def test_reopen3(self):

def test_reopen4(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
tmp = os.path.join(tempfile.gettempdir(), "t.sqlite")
tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString()
query = QUrl.toPercentEncoding("SELECT * FROM vtab")
l = QgsVectorLayer("%s?layer=ogr:%s:vtab&query=%s&uid=objectid&nogeometry" % (tmp, source, query), "vtab2", "virtual", False)
self.assertEqual(l.isValid(), True)
@@ -390,7 +390,7 @@ def test_reopen4(self):
self.assertEqual(suma, 3064.0)

def test_refLayer(self):
l1 = QgsVectorLayer("file:///" + os.path.join(self.testDataDir, "delimitedtext/test.csv").replace("\\", "/") + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
self.assertEqual(l1.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l1)

@@ -403,7 +403,7 @@ def test_refLayer(self):
print sum([f.id() for f in l2.getFeatures()])

def test_refLayers(self):
l1 = QgsVectorLayer("file:///" + os.path.join(self.testDataDir, "delimitedtext/test.csv").replace("\\", "/") + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
self.assertEqual(l1.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l1)

@@ -418,18 +418,18 @@ def test_refLayers(self):
QgsMapLayerRegistry.instance().removeMapLayer(l2.id())

def test_refLayers2(self):
l1 = QgsVectorLayer("file:///" + os.path.join(self.testDataDir, "delimitedtext/test.csv").replace("\\", "/") + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
self.assertEqual(l1.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l1)

# referenced layers cannot be stored !
tmp = os.path.join(tempfile.gettempdir(), "t.sqlite")
tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString()
l2 = QgsVectorLayer("%s?layer_ref=%s" % (tmp, l1.id()), "tt", "virtual", False)
self.assertEqual(l2.isValid(), False)
self.assertEqual("Cannot store referenced layers" in l2.dataProvider().error().message(), True)

def test_sql(self):
l1 = QgsVectorLayer("file:///" + os.path.join(self.testDataDir, "delimitedtext/test.csv").replace("\\", "/") + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
self.assertEqual(l1.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l1)

0 comments on commit f5b615a

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