Skip to content
Permalink
Browse files
Cleanup after shapefile tests
  • Loading branch information
m-kuhn committed May 28, 2015
1 parent 4ddfca7 commit d0bd9a24744ca303646c9a0cfa33946ac2d99bdd
Showing with 16 additions and 12 deletions.
  1. +16 −12 tests/src/python/test_provider_shapefile.py
@@ -29,27 +29,30 @@
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
TEST_DATA_DIR = unitTestDataPath()


class TestPyQgsPostgresProvider(TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
# Create test layer
basetestpath = tempfile.mkdtemp()
repackfilepath = tempfile.mkdtemp()
cls.basetestpath = tempfile.mkdtemp()
cls.repackfilepath = tempfile.mkdtemp()

srcpath = os.path.join(TEST_DATA_DIR, 'provider')
for file in glob.glob(os.path.join(srcpath, 'shapefile.*')):
shutil.copy(os.path.join(srcpath, file),basetestpath)
shutil.copy(os.path.join(srcpath, file),repackfilepath)
cls.basetestfile = os.path.join(basetestpath, 'shapefile.shp' )
cls.repackfile = os.path.join(repackfilepath, 'shapefile.shp')
cls.vl = QgsVectorLayer(u'{}|layerid=0'.format(cls.basetestfile), u'test', u'ogr' )
assert(cls.vl.isValid())
shutil.copy(os.path.join(srcpath, file), cls.basetestpath)
shutil.copy(os.path.join(srcpath, file), cls.repackfilepath)
cls.basetestfile = os.path.join(cls.basetestpath, 'shapefile.shp')
cls.repackfile = os.path.join(cls.repackfilepath, 'shapefile.shp')
cls.vl = QgsVectorLayer(u'{}|layerid=0'.format(cls.basetestfile), u'test', u'ogr')
assert (cls.vl.isValid())
cls.provider = cls.vl.dataProvider()

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
shutil.rmtree(cls.basetestpath)
shutil.rmtree(cls.repackfilepath)

def testUnique(self):
"""
@@ -58,20 +61,21 @@ def testUnique(self):
in the future even better.
"""
assert set(self.provider.uniqueValues(1)) == set([-200, 100, 200, 300, 400])
assert set([u'Apple', u'Honey', u'Orange', u'Pear']) == set(self.provider.uniqueValues(2)), 'Got {}'.format(set(self.provider.uniqueValues(2)))
assert set([u'Apple', u'Honey', u'Orange', u'Pear']) == set(self.provider.uniqueValues(2)), 'Got {}'.format(
set(self.provider.uniqueValues(2)))

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

ids = [f.id() for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('pk=1'))]
ids = [f.id() for f in vl.getFeatures(QgsFeatureRequest().setFilterExpression('pk=1'))]
vl.setSelectedFeatures(ids)
assert vl.selectedFeaturesIds() == ids, vl.selectedFeaturesIds()
assert vl.pendingFeatureCount() == 5, vl.pendingFeatureCount()
assert vl.pendingFeatureCount() == 5, vl.pendingFeatureCount()
assert vl.startEditing()
assert vl.deleteFeature(3)
assert vl.commitChanges()
assert vl.selectedFeatureCount() == 0 or vl.selectedFeatures()[0]['pk'] == 1


if __name__ == '__main__':
unittest.main()

0 comments on commit d0bd9a2

Please sign in to comment.