@@ -33,17 +33,18 @@ class TestQgsVirtualLayerTask(unittest.TestCase):
33
33
34
34
def setUp (self ):
35
35
self .testDataDir = unitTestDataPath ()
36
- self .success = False
37
- self .fail = False
36
+ self ._success = False
37
+ self ._fail = False
38
38
self .ids = None
39
39
self .task = None
40
40
41
41
def onSuccess (self ):
42
- self .success = True
42
+ self ._success = True
43
43
self .ids = [f .id () for f in self .task .layer ().getFeatures ()]
44
44
45
45
def onFail (self ):
46
- self .fail = True
46
+ self ._fail = True
47
+ self ._exceptionText = self .task .exceptionText ()
47
48
48
49
def test (self ):
49
50
l1 = QgsVectorLayer (os .path .join (self .testDataDir , "france_parts.shp" ), "françéà" , "ogr" , QgsVectorLayer .LayerOptions (False ))
@@ -61,14 +62,29 @@ def test(self):
61
62
self .task .taskTerminated .connect (self .onFail )
62
63
63
64
QgsApplication .taskManager ().addTask (self .task )
64
- while not self .success and not self .fail :
65
+ while not self ._success and not self ._fail :
65
66
QCoreApplication .processEvents ()
66
67
67
- self .assertTrue (self .success )
68
- self .assertFalse (self .fail )
68
+ self .assertTrue (self ._success )
69
+ self .assertFalse (self ._fail )
69
70
70
71
self .assertEqual (len (self .ids ), 4 )
71
72
73
+ # Test exception
74
+ self ._success = False
75
+ self ._fail = False
76
+ df .setQuery ('select *' )
77
+ self .task = QgsVirtualLayerTask (df )
78
+ self .task .taskCompleted .connect (self .onSuccess )
79
+ self .task .taskTerminated .connect (self .onFail )
80
+ QgsApplication .taskManager ().addTask (self .task )
81
+ while not self ._success and not self ._fail :
82
+ QCoreApplication .processEvents ()
83
+
84
+ self .assertFalse (self ._success )
85
+ self .assertTrue (self ._fail )
86
+ self .assertEqual (self ._exceptionText , 'Query preparation error on PRAGMA table_info(_tview): no tables specified' , self ._exceptionText )
87
+
72
88
73
89
if __name__ == '__main__' :
74
90
unittest .main ()
0 commit comments