Skip to content

Commit

Permalink
Expand tests
Browse files Browse the repository at this point in the history
(cherry picked from commit e93bacd)
  • Loading branch information
nyalldawson committed Feb 26, 2020
1 parent 0d158a3 commit 7f75775
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/src/python/test_provider_shapefile.py
Expand Up @@ -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()
Expand Down

0 comments on commit 7f75775

Please sign in to comment.