Skip to content
Permalink
Browse files

Expand tests

  • Loading branch information
nyalldawson committed Feb 10, 2020
1 parent c0581ff commit e93bacd98749005d4b383fde5873c8e0ea90367b
Showing with 17 additions and 0 deletions.
  1. +17 −0 tests/src/python/test_provider_shapefile.py
@@ -630,31 +630,48 @@ def testEncoding(self):
vl = QgsVectorLayer(file_path)
self.assertTrue(vl.isValid())
self.assertEqual(vl.dataProvider().encoding(), 'ISO-8859-1')
self.assertEqual(next(vl.getFeatures())[1], 'äöü')

file_path = os.path.join(TEST_DATA_DIR, 'shapefile', 'iso-8859-1_ldid.shp')
vl = QgsVectorLayer(file_path)
self.assertTrue(vl.isValid())
self.assertEqual(vl.dataProvider().encoding(), 'ISO-8859-1')
self.assertEqual(next(vl.getFeatures())[1], 'äöü')

file_path = os.path.join(TEST_DATA_DIR, 'shapefile', 'latin1.shp')
vl = QgsVectorLayer(file_path)
self.assertTrue(vl.isValid())
self.assertEqual(vl.dataProvider().encoding(), 'ISO-8859-1')
self.assertEqual(next(vl.getFeatures())[1], 'äöü')

file_path = os.path.join(TEST_DATA_DIR, 'shapefile', 'utf8.shp')
vl = QgsVectorLayer(file_path)
self.assertTrue(vl.isValid())
self.assertEqual(vl.dataProvider().encoding(), 'UTF-8')
self.assertEqual(next(vl.getFeatures())[1], 'äöü')

file_path = os.path.join(TEST_DATA_DIR, 'shapefile', 'windows-1252.shp')
vl = QgsVectorLayer(file_path)
self.assertTrue(vl.isValid())
self.assertEqual(vl.dataProvider().encoding(), 'windows-1252')
self.assertEqual(next(vl.getFeatures())[1], 'äöü')

file_path = os.path.join(TEST_DATA_DIR, 'shapefile', 'windows-1252_ldid.shp')
vl = QgsVectorLayer(file_path)
self.assertTrue(vl.isValid())
self.assertEqual(vl.dataProvider().encoding(), 'windows-1252')
self.assertEqual(next(vl.getFeatures())[1], 'äöü')

file_path = os.path.join(TEST_DATA_DIR, 'shapefile', 'system_encoding.shp')
vl = QgsVectorLayer(file_path)
self.assertTrue(vl.isValid())
# no encoding hints, so it should default to UTF-8 (which is wrong for this particular file, but the correct guess to make first!)
self.assertEqual(vl.dataProvider().encoding(), 'UTF-8')
self.assertNotEqual(next(vl.getFeatures())[1], 'äöü')
# set to correct encoding
vl.dataProvider().setEncoding('ISO-8859-1')
self.assertEqual(vl.dataProvider().encoding(), 'ISO-8859-1')
self.assertEqual(next(vl.getFeatures())[1], 'äöü')

def testCreateAttributeIndex(self):
tmpdir = tempfile.mkdtemp()

0 comments on commit e93bacd

Please sign in to comment.
You can’t perform that action at this time.