Module Expr Str TryExcept body Import alias Assign NameStore NameLoad handlers ExceptHandler type NameLoad body Assign NameStore NameLoad ImportFrom alias alias FunctionDef arguments args defaults body If NameLoad body Return NameLoad Assign NameStore Str TryExcept body Expr Call AttributeLoad NameLoad attr NameLoad Return NameLoad handlers ExceptHandler body Return NameLoad decorator_list FunctionDef arguments args defaults body If NameLoad body Return NameLoad ImportFrom alias Return Call NameLoad GeneratorExp Call NameLoad NameLoad comprehension NameStore Call AttributeLoad NameLoad attr Str decorator_list Assign NameStore Call NameLoad FunctionDef arguments args NameParam NameParam defaults body Return Str decorator_list ClassDef bases AttributeLoad NameLoad attr NameLoad body FunctionDef arguments args NameParam defaults body Assign NameStore Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str decorator_list Call AttributeLoad NameLoad attr NameLoad Str FunctionDef arguments args NameParam defaults body Assign NameStore Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad With Call AttributeLoad NameLoad attr NameLoad Str keyword Num body Assign AttributeStore NameLoad attr Str decorator_list Call AttributeLoad NameLoad attr NameLoad Str FunctionDef arguments args NameParam defaults body Assign NameStore Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad With Call AttributeLoad NameLoad attr NameLoad Str keyword Num body Assign AttributeStore NameLoad attr Str Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Num decorator_list Call AttributeLoad NameLoad attr NameLoad Str FunctionDef arguments args NameParam defaults body Assign NameStore Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad keyword Dict keyword Dict With Call AttributeLoad NameLoad attr NameLoad Str keyword Num body Assign AttributeStore NameLoad attr Str Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Num decorator_list Call AttributeLoad NameLoad attr NameLoad Str FunctionDef arguments args NameParam defaults body Assign NameStore Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad keyword Dict keyword Dict Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Str Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr decorator_list Call AttributeLoad NameLoad attr NameLoad Str FunctionDef arguments args NameParam defaults body Assign NameStore Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad keyword Dict keyword Dict Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Str Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr decorator_list Call AttributeLoad NameLoad attr NameLoad Str FunctionDef arguments args NameParam defaults body Assign NameStore Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad keyword Dict keyword Dict Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Str Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list Call AttributeLoad NameLoad attr NameLoad Str FunctionDef arguments args NameParam defaults body Assign NameStore Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Str Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list Call AttributeLoad NameLoad attr NameLoad Str FunctionDef arguments args NameParam defaults body Assign NameStore Str TryExcept body Expr Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad keyword Dict keyword Dict handlers ExceptHandler body Pass orelse Expr Call AttributeLoad NameLoad attr Str decorator_list Call AttributeLoad NameLoad attr NameLoad Str decorator_list
N/A N/A  Test some usage of Trait classes when the code is cythonized.

The tests reflects some of the patterns needed in different applications. They
probably don't cover all of the user case.

Each test case is written as if the test code was in a separate module then
compiled with Cython Inline before evaluation the produced object behaves
properly.

The tests need a Cython version > 0.19 and a compiler.

 N/A N/A N/A cython N/A no_cython False N/A N/A N/A ImportError N/A N/A no_cython True testing.unittest_tools unittest UnittestTools has_no_compiler N/A N/A N/A N/A N/A no_cython N/A N/A True N/A code return 1+1 N/A N/A N/A N/A N/A cython inline code N/A False N/A N/A N/A N/A True N/A cython_version N/A N/A N/A N/A N/A no_cython N/A N/A None Cython.Compiler.Version version N/A N/A tuple N/A N/A int v N/A v N/A N/A version split . N/A N/A SKIP_TEST N/A has_no_compiler _always_object_type N/A N/A arg context N/A N/A N/A object N/A CythonizedTraitsTestCase N/A N/A unittest TestCase UnittestTools N/A test_simple_default_methods N/A N/A self N/A N/A N/A code 
from traits.api import HasTraits, Str

class Test(HasTraits):
    name = Str

    def _name_default(self):
        return 'Joe'

return Test()
 N/A obj N/A N/A cython inline code N/A N/A N/A self assertEqual N/A obj name Joe N/A N/A N/A unittest skipIf SKIP_TEST Missing Cython and/or compiler test_basic_events N/A N/A self N/A N/A N/A code 
from traits.api import HasTraits, Str

class Test(HasTraits):
    name = Str

return Test()
 N/A obj N/A N/A cython inline code N/A N/A N/A self assertTraitChanges obj name count 1 N/A N/A N/A obj name changing_name N/A N/A N/A unittest skipIf SKIP_TEST Missing Cython and/or compiler test_on_trait_static_handlers N/A N/A self N/A N/A N/A code 
from traits.api import HasTraits, Str, Int

class Test(HasTraits):
    name = Str
    value = Int

    def _name_changed(self):
        self.value += 1

return Test()
 N/A obj N/A N/A cython inline code get_type _always_object_type force True N/A N/A N/A self assertTraitChanges obj value count 1 N/A N/A N/A obj name changing_name N/A N/A N/A self assertEqual N/A obj value 1 N/A N/A N/A unittest skipIf SKIP_TEST Missing Cython and/or compiler test_on_trait_on_trait_change_decorator N/A N/A self N/A N/A N/A code 
from traits.api import HasTraits, Str, Int, on_trait_change

class Test(HasTraits):
    name = Str
    value = Int

    @on_trait_change('name')
    def _update_value(self):
        self.value += 1

return Test()
 N/A obj N/A N/A cython inline code get_type _always_object_type force True locals N/A globals N/A N/A N/A N/A self assertTraitChanges obj value count 1 N/A N/A N/A obj name changing_name N/A N/A N/A self assertEqual N/A obj value 1 N/A N/A N/A unittest skipIf SKIP_TEST Missing Cython and/or compiler test_on_trait_properties N/A N/A self N/A N/A N/A code 
from traits.api import HasTraits, Str, Int, Property, cached_property

class Test(HasTraits):
    name = Str
    name_len = Property(depends_on='name')

    @cached_property
    def _get_name_len(self):
        return len(self.name)

return Test()
 N/A obj N/A N/A cython inline code get_type _always_object_type force True locals N/A globals N/A N/A N/A N/A self assertEqual N/A obj name_len N/A len N/A obj name N/A N/A obj name Bob N/A N/A N/A self assertEqual N/A obj name_len N/A len N/A obj name N/A N/A N/A unittest skipIf SKIP_TEST Missing Cython and/or compiler test_on_trait_properties_with_standard_getter N/A N/A self N/A N/A N/A code 
from traits.api import HasTraits, Str, Int, Property

class Test(HasTraits):
    name = Str

    def _get_name_length(self):
        return len(self.name)

    name_len = Property(_get_name_length)

return Test()
 N/A obj N/A N/A cython inline code get_type _always_object_type force True locals N/A globals N/A N/A N/A N/A self assertEqual N/A obj name_len N/A len N/A obj name N/A N/A obj name Bob N/A N/A N/A self assertEqual N/A obj name_len N/A len N/A obj name N/A N/A N/A unittest skipIf SKIP_TEST Missing Cython and/or compiler test_on_trait_aliasing N/A N/A self N/A N/A N/A code 
from traits.api import HasTraits, Str, Int, Property

def Alias(name):
    def _get_value(self):
        return getattr(self, name)
    def _set_value(self, value):
        return setattr(self, name, value)

    return Property(_get_value, _set_value)

class Test(HasTraits):
    name = Str

    funky_name = Alias('name')

return Test()
 N/A obj N/A N/A cython inline code get_type _always_object_type force True locals N/A globals N/A N/A N/A N/A self assertEqual N/A obj funky_name N/A obj name N/A N/A obj name Bob N/A N/A N/A self assertEqual N/A obj funky_name N/A obj name N/A N/A N/A unittest skipIf SKIP_TEST Missing Cython and/or compiler test_on_trait_aliasing_different_scope N/A N/A self N/A N/A N/A code 
from traits.api import HasTraits, Str, Int, Property

def _get_value(self, name):
    return getattr(self, 'name')
def _set_value(self, name, value):
    return setattr(self, 'name', value)


class Test(HasTraits):
    name = Str

    funky_name = Property(_get_value, _set_value)

return Test()
 N/A obj N/A N/A cython inline code get_type _always_object_type N/A N/A N/A self assertEqual N/A obj funky_name N/A obj name N/A N/A obj name Bob N/A N/A N/A self assertEqual N/A obj funky_name N/A obj name N/A N/A N/A unittest skipIf SKIP_TEST Missing Cython and/or compiler test_on_trait_lambda_failure N/A N/A self N/A N/A N/A code 
from traits.api import HasTraits, Str, Int, Property

def Alias(name):
    return Property(
        lambda obj: getattr(obj, name),
        lambda obj, value: setattr(obj, name, value)
    )

class Test(HasTraits):
    name = Str

    funky_name = Alias('name')

return Test()
 N/A N/A N/A N/A N/A cython inline code get_type _always_object_type force True locals N/A globals N/A N/A N/A N/A N/A N/A N/A N/A N/A self fail Unexpected results. Cython was not managing lambda as regular functions. Behaviour changed ... N/A N/A N/A unittest skipIf SKIP_TEST Missing Cython and/or compiler N/A