Skip to content
Permalink
Browse files

Make feature source/provider test handle additional fields

  • Loading branch information
nyalldawson committed Feb 20, 2018
1 parent 922776b commit 7d620e28f194d5d24dae33bf2a78f60b636a98ef
@@ -646,16 +646,16 @@ def testGetFeaturesWithGeometry(self):
self.assertTrue(f.isValid())

def testUniqueValues(self):
self.assertEqual(set(self.source.uniqueValues(1)), set([-200, 100, 200, 300, 400]))
assert set(['Apple', 'Honey', 'Orange', 'Pear', NULL]) == set(self.source.uniqueValues(2)), 'Got {}'.format(set(self.source.uniqueValues(2)))
self.assertEqual(set(self.source.uniqueValues(self.source.fields().lookupField('cnt'))), set([-200, 100, 200, 300, 400]))
assert set(['Apple', 'Honey', 'Orange', 'Pear', NULL]) == set(self.source.uniqueValues(self.source.fields().lookupField('name'))), 'Got {}'.format(set(self.source.uniqueValues(self.source.fields().lookupField('name'))))

def testMinimumValue(self):
self.assertEqual(self.source.minimumValue(1), -200)
self.assertEqual(self.source.minimumValue(2), 'Apple')
self.assertEqual(self.source.minimumValue(self.source.fields().lookupField('cnt')), -200)
self.assertEqual(self.source.minimumValue(self.source.fields().lookupField('name')), 'Apple')

def testMaximumValue(self):
self.assertEqual(self.source.maximumValue(1), 400)
self.assertEqual(self.source.maximumValue(2), 'Pear')
self.assertEqual(self.source.maximumValue(self.source.fields().lookupField('cnt')), 400)
self.assertEqual(self.source.maximumValue(self.source.fields().lookupField('name')), 'Pear')

def testAllFeatureIds(self):
ids = set([f.id() for f in self.source.getFeatures()])
@@ -277,24 +277,24 @@ def testGetFeaturesPolyFilterRectTests(self):
assert set(features) == set([1, 2, 3, 4, 5]), 'Got {} instead'.format(features)

def testMinValue(self):
self.assertEqual(self.source.minimumValue(1), -200)
self.assertEqual(self.source.minimumValue(2), 'Apple')
self.assertEqual(self.source.minimumValue(self.source.fields().lookupField('cnt')), -200)
self.assertEqual(self.source.minimumValue(self.source.fields().lookupField('name')), 'Apple')

if self.source.supportsSubsetString():
subset = self.getSubsetString()
self.source.setSubsetString(subset)
min_value = self.source.minimumValue(1)
min_value = self.source.minimumValue(self.source.fields().lookupField('cnt'))
self.source.setSubsetString(None)
self.assertEqual(min_value, 200)

def testMaxValue(self):
self.assertEqual(self.source.maximumValue(1), 400)
self.assertEqual(self.source.maximumValue(2), 'Pear')
self.assertEqual(self.source.maximumValue(self.source.fields().lookupField('cnt')), 400)
self.assertEqual(self.source.maximumValue(self.source.fields().lookupField('name')), 'Pear')

if self.source.supportsSubsetString():
subset = self.getSubsetString2()
self.source.setSubsetString(subset)
max_value = self.source.maximumValue(1)
max_value = self.source.maximumValue(self.source.fields().lookupField('cnt'))
self.source.setSubsetString(None)
self.assertEqual(max_value, 300)

@@ -330,28 +330,29 @@ def testExtent(self):
self.assertTrue(provider_extent.isNull())

def testUnique(self):
self.assertEqual(set(self.source.uniqueValues(1)), set([-200, 100, 200, 300, 400]))
assert set(['Apple', 'Honey', 'Orange', 'Pear', NULL]) == set(self.source.uniqueValues(2)), 'Got {}'.format(set(self.source.uniqueValues(2)))
self.assertEqual(set(self.source.uniqueValues(self.source.fields().lookupField('cnt'))), set([-200, 100, 200, 300, 400]))
assert set(['Apple', 'Honey', 'Orange', 'Pear', NULL]) == set(self.source.uniqueValues(2)), 'Got {}'.format(set(self.source.uniqueValues(self.source.fields().lookupField('name'))))

if self.source.supportsSubsetString():
subset = self.getSubsetString2()
self.source.setSubsetString(subset)
values = self.source.uniqueValues(1)
values = self.source.uniqueValues(self.source.fields().lookupField('cnt'))
self.source.setSubsetString(None)
self.assertEqual(set(values), set([200, 300]))

def testUniqueStringsMatching(self):
self.assertEqual(set(self.source.uniqueStringsMatching(2, 'a')), set(['Pear', 'Orange', 'Apple']))
field_index = self.source.fields().lookupField('name')
self.assertEqual(set(self.source.uniqueStringsMatching(field_index, 'a')), set(['Pear', 'Orange', 'Apple']))
# test case insensitive
self.assertEqual(set(self.source.uniqueStringsMatching(2, 'A')), set(['Pear', 'Orange', 'Apple']))
self.assertEqual(set(self.source.uniqueStringsMatching(field_index, 'A')), set(['Pear', 'Orange', 'Apple']))
# test string ending in substring
self.assertEqual(set(self.source.uniqueStringsMatching(2, 'ney')), set(['Honey']))
self.assertEqual(set(self.source.uniqueStringsMatching(field_index, 'ney')), set(['Honey']))
# test limit
result = set(self.source.uniqueStringsMatching(2, 'a', 2))
result = set(self.source.uniqueStringsMatching(field_index, 'a', 2))
self.assertEqual(len(result), 2)
self.assertTrue(result.issubset(set(['Pear', 'Orange', 'Apple'])))

assert set([u'Apple', u'Honey', u'Orange', u'Pear', NULL]) == set(self.source.uniqueValues(2)), 'Got {}'.format(set(self.source.uniqueValues(2)))
assert set([u'Apple', u'Honey', u'Orange', u'Pear', NULL]) == set(self.source.uniqueValues(field_index)), 'Got {}'.format(set(self.source.uniqueValues(field_index)))

if self.source.supportsSubsetString():
subset = self.getSubsetString2()
@@ -75,7 +75,7 @@ def testMinValues(self):
layer = createLayerWithFivePoints()
self.assertFalse(layer.dataProvider().minimumValue(-1))
self.assertFalse(layer.dataProvider().minimumValue(100))
self.assertEqual(layer.dataProvider().minimumValue(1), 'test')
self.assertEqual(layer.dataProvider().minimumValue(layer.dataProvider().fields().lookupField('cnt')), 'test')
self.assertEqual(layer.dataProvider().minimumValue(2), 1)

def testMaxValues(self):

0 comments on commit 7d620e2

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