Skip to content
Permalink
Browse files

Add test for qgsfunction.handlesnull

  • Loading branch information
m-kuhn committed Jul 1, 2018
1 parent 60730ab commit 4d5eb49f1c11105b9d101a92d567608fe1b4362d
Showing with 10 additions and 0 deletions.
  1. +10 −0 tests/src/python/test_qgsexpression.py
@@ -67,6 +67,11 @@ def no_referenced_columns_set(values, feature, parent):
def referenced_columns_set(values, feature, parent):
return 2

@qgsfunction(args=-1, group='testing', register=False, handlesnull=True)
def null_mean(values, feature, parent):
vals = [val for val in values if val != NULL]
return sum(vals) / len(vals)

def tearDown(self):
QgsExpression.unregisterFunction('testfun')

@@ -161,6 +166,11 @@ def testReferencedColumnsSet(self):
exp = QgsExpression('referenced_columns_set()')
self.assertEqual(set(exp.referencedColumns()), set(['a', 'b']))

def testHandlesNull(self):
QgsExpression.registerFunction(self.handles_null)
exp = QgsExpression('null_mean(1, 2, NULL, 3)')
self.assertEqual(set(exp.evaluate()), 2)

def testCantOverrideBuiltinsWithUnregister(self):
success = QgsExpression.unregisterFunction("sqrt")
self.assertFalse(success)

0 comments on commit 4d5eb49

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