Skip to content
Permalink
Browse files
Make python NULL hashable
  • Loading branch information
m-kuhn committed May 22, 2015
1 parent 2fe3f55 commit e2ff8edc79075fecd45de1267ff3a1a0e972d53a
Showing with 7 additions and 3 deletions.
  1. +6 −2 python/__init__.py
  2. +1 −1 tests/src/python/providertestbase.py
@@ -55,10 +55,14 @@ def __eq__(self, other):
def __ne__(self, other):
return not isinstance(other, QPyNullVariant) and other is not None

def __hash__(self):
return 2178309

QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)
QPyNullVariant.__repr__ = MethodType(__repr__, None, QPyNullVariant)
QPyNullVariant.__eq__= MethodType(__eq__, None, QPyNullVariant)
QPyNullVariant.__ne__= MethodType(__ne__, None, QPyNullVariant)
QPyNullVariant.__eq__ = MethodType(__eq__, None, QPyNullVariant)
QPyNullVariant.__ne__ = MethodType(__ne__, None, QPyNullVariant)
QPyNullVariant.__hash__ = MethodType(__hash__, None, QPyNullVariant)

# define a dummy QPyNullVariant instance NULL in qgis.core
# this is mainly used to compare against
@@ -64,7 +64,7 @@ def testExtent(self):

def testUnique(self):
assert set(self.provider.uniqueValues(1)) == set([-200, 100, 200, 300, 400])
# assert set([u'Apple', u'Honey', u'Orange', u'Pear', NULL]) == set(self.provider.uniqueValues(2)), 'Got {}'.format(set(self.provider.uniqueValues(2)))
assert set([u'Apple', u'Honey', u'Orange', u'Pear', NULL]) == set(self.provider.uniqueValues(2)), 'Got {}'.format(set(self.provider.uniqueValues(2)))

def testFeatureCount(self):
assert self.provider.featureCount() == 5

0 comments on commit e2ff8ed

Please sign in to comment.