From 6db166890bcc0a880248ef390dbacfcaa1e9967a Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 1 Apr 2010 20:34:59 +0200 Subject: [PATCH] extended test cases --- tests/run/dict_get.pyx | 19 +++++++++++++++++++ tests/run/dict_getitem.pyx | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/tests/run/dict_get.pyx b/tests/run/dict_get.pyx index f27a8137..d5d905e5 100644 --- a/tests/run/dict_get.pyx +++ b/tests/run/dict_get.pyx @@ -1,3 +1,8 @@ + +cimport cython + +@cython.test_assert_path_exists("//PythonCapiCallNode") +@cython.test_fail_if_path_exists("//AttributeNode") def get(dict d, key): """ >>> d = { 1: 10 } @@ -38,6 +43,9 @@ def get(dict d, 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): """ >>> d = { 1: 10 } @@ -69,3 +77,14 @@ def get_default(dict d, key, default): ValueError """ 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 diff --git a/tests/run/dict_getitem.pyx b/tests/run/dict_getitem.pyx index b4673d6c..f40c31b8 100644 --- a/tests/run/dict_getitem.pyx +++ b/tests/run/dict_getitem.pyx @@ -32,3 +32,12 @@ def test(dict d, index): cdef class Subscriptable: def __getitem__(self, 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 -- 2.26.2