Dict getitem test.
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 23 Feb 2010 07:44:19 +0000 (23:44 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 23 Feb 2010 07:44:19 +0000 (23:44 -0800)
tests/run/dict_getitme.pyx [new file with mode: 0644]

diff --git a/tests/run/dict_getitme.pyx b/tests/run/dict_getitme.pyx
new file mode 100644 (file)
index 0000000..c43e5a2
--- /dev/null
@@ -0,0 +1,25 @@
+def test(dict d, index):
+    """
+    >>> d = { 1: 10 }
+    >>> test(d, 1)
+    10
+
+    >>> test(d, 2)
+    Traceback (most recent call last):
+    ...
+    KeyError: 2
+
+    >>> test(d, (1,2))
+    Traceback (most recent call last):
+    ...
+    KeyError: (1, 2)
+
+    >>> class Unhashable:
+    ...    def __hash__(self):
+    ...        raise ValueError
+    >>> test(d, Unhashable())
+    Traceback (most recent call last):
+    ...
+    ValueError
+    """
+    return d[index]