@@ -33,17 +33,18 @@ class TestQgsVirtualLayerTask(unittest.TestCase):
3333
3434 def setUp (self ):
3535 self .testDataDir = unitTestDataPath ()
36- self .success = False
37- self .fail = False
36+ self ._success = False
37+ self ._fail = False
3838 self .ids = None
3939 self .task = None
4040
4141 def onSuccess (self ):
42- self .success = True
42+ self ._success = True
4343 self .ids = [f .id () for f in self .task .layer ().getFeatures ()]
4444
4545 def onFail (self ):
46- self .fail = True
46+ self ._fail = True
47+ self ._exceptionText = self .task .exceptionText ()
4748
4849 def test (self ):
4950 l1 = QgsVectorLayer (os .path .join (self .testDataDir , "france_parts.shp" ), "françéà" , "ogr" , QgsVectorLayer .LayerOptions (False ))
@@ -61,14 +62,29 @@ def test(self):
6162 self .task .taskTerminated .connect (self .onFail )
6263
6364 QgsApplication .taskManager ().addTask (self .task )
64- while not self .success and not self .fail :
65+ while not self ._success and not self ._fail :
6566 QCoreApplication .processEvents ()
6667
67- self .assertTrue (self .success )
68- self .assertFalse (self .fail )
68+ self .assertTrue (self ._success )
69+ self .assertFalse (self ._fail )
6970
7071 self .assertEqual (len (self .ids ), 4 )
7172
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+
7288
7389if __name__ == '__main__' :
7490 unittest .main ()
0 commit comments