From 185ba1f683baf9b03e609949de614eb0ebdcb8ff Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 10 Mar 2011 18:29:39 -0500 Subject: [PATCH] Adjust cdef_members_T517 tests to reflect visibility for struct attributes. Struct attributes can have private or readonly, but not public, Python visibility. Readonly structs are currently converted to dicts on the fly for each call getting the struct attribute value. The dict-generation code is currently broken for C++ (error: declaration does not declare anything), so tests/run/cdef_members_T517.pyx currently fails a C++ test. However, we hope to soon replace it with full blown Python classes representing structs/unions/enums which will work for both C and C++. --- tests/errors/cdef_members_T517.pyx | 1 - tests/run/cdef_members_T517.pyx | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/errors/cdef_members_T517.pyx b/tests/errors/cdef_members_T517.pyx index ee95a408..9867aca6 100644 --- a/tests/errors/cdef_members_T517.pyx +++ b/tests/errors/cdef_members_T517.pyx @@ -20,7 +20,6 @@ _ERRORS = u""" 6:24: C attribute of type 'VoidP' cannot be accessed from Python 6:24: Cannot convert 'VoidP' to Python object 6:24: Cannot convert Python object to 'VoidP' -14:22: C attribute of type 'Foo' cannot be accessed from Python 14:22: Cannot convert Python object to 'Foo' """ diff --git a/tests/run/cdef_members_T517.pyx b/tests/run/cdef_members_T517.pyx index 82699de4..f3e2080a 100644 --- a/tests/run/cdef_members_T517.pyx +++ b/tests/run/cdef_members_T517.pyx @@ -76,6 +76,20 @@ AttributeError: ... >>> b.c2 = A() #doctest: +ELLIPSIS Traceback (most recent call last): AttributeError: ... + +>>> bar = Bar() + +>>> bar.foo0 #doctest: +ELLIPSIS +Traceback (most recent call last): +AttributeError: ... + +>>> type(bar.foo1) + +>>> bar.foo1 +{'i': 0} +>>> bar.foo1['i'] = 2 +>>> bar.foo1 +{'i': 0} """ import sys @@ -138,3 +152,13 @@ cdef class B: def __cinit__(self): self.b0 = self.b1 = self.b2 = [] self.c0 = self.c1 = self.c2 = A() + + +ctypedef struct Foo: + int i + + +cdef class Bar: + cdef Foo foo0 + cdef readonly Foo foo1 + pass -- 2.26.2