Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add test for qgsfunction.handlesnull
  • Loading branch information
m-kuhn committed Jul 1, 2018
1 parent 60730ab commit 4d5eb49
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/src/python/test_qgsexpression.py
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4d5eb49

Please sign in to comment.