Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved test for cascaded comparison coercions

  • Loading branch information...
commit f7cd93f2331294f5a487a64184f5172cab4eb2ee 1 parent a6abc08
scoder scoder authored
Showing with 24 additions and 1 deletion.
  1. +24 −1 tests/run/inop.pyx
25 tests/run/inop.pyx
View
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.