29
29
QGISAPP , CANVAS , IFACE , PARENT = getQgisTestApp ()
30
30
TEST_DATA_DIR = unitTestDataPath ()
31
31
32
+
32
33
class TestPyQgsPostgresProvider (TestCase , ProviderTestCase ):
33
34
@classmethod
34
35
def setUpClass (cls ):
35
36
"""Run before all tests"""
36
37
# Create test layer
37
- basetestpath = tempfile .mkdtemp ()
38
- repackfilepath = tempfile .mkdtemp ()
38
+ cls . basetestpath = tempfile .mkdtemp ()
39
+ cls . repackfilepath = tempfile .mkdtemp ()
39
40
40
41
srcpath = os .path .join (TEST_DATA_DIR , 'provider' )
41
42
for file in glob .glob (os .path .join (srcpath , 'shapefile.*' )):
42
- shutil .copy (os .path .join (srcpath , file ),basetestpath )
43
- shutil .copy (os .path .join (srcpath , file ),repackfilepath )
44
- cls .basetestfile = os .path .join (basetestpath , 'shapefile.shp' )
45
- cls .repackfile = os .path .join (repackfilepath , 'shapefile.shp' )
46
- cls .vl = QgsVectorLayer (u'{}|layerid=0' .format (cls .basetestfile ), u'test' , u'ogr' )
47
- assert (cls .vl .isValid ())
43
+ shutil .copy (os .path .join (srcpath , file ), cls . basetestpath )
44
+ shutil .copy (os .path .join (srcpath , file ), cls . repackfilepath )
45
+ cls .basetestfile = os .path .join (cls . basetestpath , 'shapefile.shp' )
46
+ cls .repackfile = os .path .join (cls . repackfilepath , 'shapefile.shp' )
47
+ cls .vl = QgsVectorLayer (u'{}|layerid=0' .format (cls .basetestfile ), u'test' , u'ogr' )
48
+ assert (cls .vl .isValid ())
48
49
cls .provider = cls .vl .dataProvider ()
49
50
50
51
@classmethod
51
52
def tearDownClass (cls ):
52
53
"""Run after all tests"""
54
+ shutil .rmtree (cls .basetestpath )
55
+ shutil .rmtree (cls .repackfilepath )
53
56
54
57
def testUnique (self ):
55
58
"""
@@ -58,20 +61,21 @@ def testUnique(self):
58
61
in the future even better.
59
62
"""
60
63
assert set (self .provider .uniqueValues (1 )) == set ([- 200 , 100 , 200 , 300 , 400 ])
61
- assert set ([u'Apple' , u'Honey' , u'Orange' , u'Pear' ]) == set (self .provider .uniqueValues (2 )), 'Got {}' .format (set (self .provider .uniqueValues (2 )))
64
+ assert set ([u'Apple' , u'Honey' , u'Orange' , u'Pear' ]) == set (self .provider .uniqueValues (2 )), 'Got {}' .format (
65
+ set (self .provider .uniqueValues (2 )))
62
66
63
67
def testRepack (self ):
64
- print 'Working with {}' .format (self .repackfile )
65
68
vl = QgsVectorLayer (u'{}|layerid=0' .format (self .repackfile ), u'test' , u'ogr' )
66
69
67
- ids = [f .id () for f in vl .getFeatures ( QgsFeatureRequest ().setFilterExpression ('pk=1' ))]
70
+ ids = [f .id () for f in vl .getFeatures (QgsFeatureRequest ().setFilterExpression ('pk=1' ))]
68
71
vl .setSelectedFeatures (ids )
69
72
assert vl .selectedFeaturesIds () == ids , vl .selectedFeaturesIds ()
70
- assert vl .pendingFeatureCount () == 5 , vl .pendingFeatureCount ()
73
+ assert vl .pendingFeatureCount () == 5 , vl .pendingFeatureCount ()
71
74
assert vl .startEditing ()
72
75
assert vl .deleteFeature (3 )
73
76
assert vl .commitChanges ()
74
77
assert vl .selectedFeatureCount () == 0 or vl .selectedFeatures ()[0 ]['pk' ] == 1
75
78
79
+
76
80
if __name__ == '__main__' :
77
81
unittest .main ()
0 commit comments