aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlexander Jones <aj@dneg.com>2012-04-18 21:51:15 +0100
committerHugo Parente Lima <hugo.lima@openbossa.org>2012-04-19 00:22:44 +0200
commit6f93c2029e9f076de1be7d8f674b3c99f664d0a1 (patch)
tree22d4bc8fc297c3264b11fe2aad33583c2185ad34 /tests
parentf011ce2cb9e2b93a748874de007232ec88cc8ac1 (diff)
Add hash-function for QModelIndex and QPersistenModelIndex
Change-Id: I2725e78a1006fbee54894f202997e2e408998551 Task-number: PYSIDE-41 Reviewed-by: Hugo Parente Lima <hugo.lima@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/QtGui/CMakeLists.txt1
-rw-r--r--tests/QtGui/bug_PYSIDE-41.py44
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/QtGui/CMakeLists.txt b/tests/QtGui/CMakeLists.txt
index 9bac91301..1f88bf5f1 100644
--- a/tests/QtGui/CMakeLists.txt
+++ b/tests/QtGui/CMakeLists.txt
@@ -81,6 +81,7 @@ PYSIDE_TEST(bug_1002.py)
PYSIDE_TEST(bug_1006.py)
PYSIDE_TEST(bug_1048.py)
PYSIDE_TEST(bug_1077.py)
+PYSIDE_TEST(bug_PYSIDE-41.py)
PYSIDE_TEST(customproxywidget_test.py)
PYSIDE_TEST(deepcopy_test.py)
PYSIDE_TEST(event_filter_test.py)
diff --git a/tests/QtGui/bug_PYSIDE-41.py b/tests/QtGui/bug_PYSIDE-41.py
new file mode 100644
index 000000000..0ca7d908e
--- /dev/null
+++ b/tests/QtGui/bug_PYSIDE-41.py
@@ -0,0 +1,44 @@
+# TODO:
+# move this to QtCore -- QStringListModel is part of QtGui and there is no
+# simple model class appropriate for this test in QtCore.
+
+import unittest
+
+from PySide.QtCore import *
+from PySide.QtGui import *
+
+
+class TestBugPYSIDE41(unittest.TestCase):
+
+ def testIt(self):
+
+ # list of single-character strings
+ strings = list('abcdefghijklmnopqrstuvwxyz')
+
+ model = QStringListModel(strings)
+
+ # Test hashing of both QModelIndex and QPersistentModelIndex
+ indexFunctions = []
+ indexFunctions.append(model.index)
+ indexFunctions.append(lambda i: QPersistentModelIndex(model.index(i)))
+
+ for indexFunction in indexFunctions:
+
+ # If two objects compare equal, their hashes MUST also be equal. (The
+ # reverse is not a requirement.)
+ for i, _ in enumerate(strings):
+ index1 = indexFunction(i)
+ index2 = indexFunction(i)
+ self.assertEqual(index1, index2)
+ self.assertEqual(hash(index1), hash(index2))
+
+ # Adding the full set of indexes to itself is a no-op.
+ allIndexes1 = set(indexFunction(i) for i, _ in enumerate(strings))
+ allIndexes2 = set(indexFunction(i) for i, _ in enumerate(strings))
+ allIndexesCombined = allIndexes1 & allIndexes2
+ self.assertEqual(allIndexes1, allIndexesCombined)
+ self.assertEqual(allIndexes2, allIndexesCombined)
+
+
+if __name__ == '__main__':
+ unittest.main()