Skip to content

Commit d0bd9a2

Browse files
committedMay 28, 2015
Cleanup after shapefile tests
1 parent 4ddfca7 commit d0bd9a2

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed
 

‎tests/src/python/test_provider_shapefile.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,30 @@
2929
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
3030
TEST_DATA_DIR = unitTestDataPath()
3131

32+
3233
class TestPyQgsPostgresProvider(TestCase, ProviderTestCase):
3334
@classmethod
3435
def setUpClass(cls):
3536
"""Run before all tests"""
3637
# Create test layer
37-
basetestpath = tempfile.mkdtemp()
38-
repackfilepath = tempfile.mkdtemp()
38+
cls.basetestpath = tempfile.mkdtemp()
39+
cls.repackfilepath = tempfile.mkdtemp()
3940

4041
srcpath = os.path.join(TEST_DATA_DIR, 'provider')
4142
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())
4849
cls.provider = cls.vl.dataProvider()
4950

5051
@classmethod
5152
def tearDownClass(cls):
5253
"""Run after all tests"""
54+
shutil.rmtree(cls.basetestpath)
55+
shutil.rmtree(cls.repackfilepath)
5356

5457
def testUnique(self):
5558
"""
@@ -58,20 +61,21 @@ def testUnique(self):
5861
in the future even better.
5962
"""
6063
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)))
6266

6367
def testRepack(self):
64-
print 'Working with {}'.format(self.repackfile)
6568
vl = QgsVectorLayer(u'{}|layerid=0'.format(self.repackfile), u'test', u'ogr')
6669

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'))]
6871
vl.setSelectedFeatures(ids)
6972
assert vl.selectedFeaturesIds() == ids, vl.selectedFeaturesIds()
70-
assert vl.pendingFeatureCount() == 5, vl.pendingFeatureCount()
73+
assert vl.pendingFeatureCount() == 5, vl.pendingFeatureCount()
7174
assert vl.startEditing()
7275
assert vl.deleteFeature(3)
7376
assert vl.commitChanges()
7477
assert vl.selectedFeatureCount() == 0 or vl.selectedFeatures()[0]['pk'] == 1
7578

79+
7680
if __name__ == '__main__':
7781
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.