Commit 6db16689 authored by Stefan Behnel's avatar Stefan Behnel

extended test cases

parent a0ede829
cimport cython
@cython.test_assert_path_exists("//PythonCapiCallNode")
@cython.test_fail_if_path_exists("//AttributeNode")
def get(dict d, key): def get(dict d, key):
""" """
>>> d = { 1: 10 } >>> d = { 1: 10 }
...@@ -38,6 +43,9 @@ def get(dict d, key): ...@@ -38,6 +43,9 @@ def get(dict d, key):
""" """
return d.get(key) return d.get(key)
@cython.test_assert_path_exists("//PythonCapiCallNode")
@cython.test_fail_if_path_exists("//AttributeNode")
def get_default(dict d, key, default): def get_default(dict d, key, default):
""" """
>>> d = { 1: 10 } >>> d = { 1: 10 }
...@@ -69,3 +77,14 @@ def get_default(dict d, key, default): ...@@ -69,3 +77,14 @@ def get_default(dict d, key, default):
ValueError ValueError
""" """
return d.get(key, default) return d.get(key, default)
@cython.test_assert_path_exists("//PythonCapiCallNode")
@cython.test_fail_if_path_exists("//AttributeNode")
def get_in_condition(dict d, key, expected_result):
"""
>>> d = dict(a=1, b=2)
>>> getitem_in_condition(d, 'a', 1)
True
"""
return d.get(key) is expected_result
...@@ -32,3 +32,12 @@ def test(dict d, index): ...@@ -32,3 +32,12 @@ def test(dict d, index):
cdef class Subscriptable: cdef class Subscriptable:
def __getitem__(self, key): def __getitem__(self, key):
return key return key
def getitem_in_condition(dict d, key, expected_result):
"""
>>> d = dict(a=1, b=2)
>>> getitem_in_condition(d, 'a', 1)
True
"""
return d[key] is expected_result
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment