From f7cd93f2331294f5a487a64184f5172cab4eb2ee Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 11 Nov 2012 09:44:50 +0100 Subject: [PATCH] improved test for cascaded comparison coercions --- tests/run/inop.pyx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/run/inop.pyx b/tests/run/inop.pyx index 481c60c..b68a47d 100644 --- a/tests/run/inop.pyx +++ b/tests/run/inop.pyx @@ -377,12 +377,17 @@ def test_inop_cascaded(x): """ return 1 != x in [2] +### The following tests are copied from CPython's test_grammar.py. +### They look stupid, but the nice thing about them is that Cython +### treats '1' as a C integer constant that triggers Python object +### coercion for the 'in' operator here, whereas the left side of +### the cascade can be evaluated entirely in C space. + def test_inop_cascaded_one(): """ >>> test_inop_cascaded_one() False """ - # copied from CPython's test_grammar.py return 1 < 1 > 1 == 1 >= 1 <= 1 != 1 in 1 not in 1 is 1 is not 1 def test_inop_cascaded_int_orig(int x): @@ -392,6 +397,24 @@ def test_inop_cascaded_int_orig(int x): """ return 1 < 1 > 1 == 1 >= 1 <= 1 != x in 1 not in 1 is 1 is not 1 +def test_inop_cascaded_one_err(): + """ + >>> test_inop_cascaded_one_err() # doctest: +ELLIPSIS + Traceback (most recent call last): + TypeError:... itera... + """ + return 1 == 1 >= 1 <= 1 in 1 not in 1 is 1 is not 1 + +def test_inop_cascaded_int_orig_err(int x): + """ + >>> test_inop_cascaded_int_orig_err(1) # doctest: +ELLIPSIS + Traceback (most recent call last): + TypeError:... itera... + """ + return 1 == 1 >= 1 <= 1 == x in 1 not in 1 is 1 is not 1 + +### + def test_inop_cascaded_int(int x): """ >>> test_inop_cascaded_int(1) -- 2.7.4