Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for property deletion (#67) #138

Merged
merged 2 commits into from
Feb 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion traits/ctraits.c
Original file line number Diff line number Diff line change
Expand Up @@ -2594,8 +2594,12 @@ setattr_validate_property ( trait_object * traito,
PyObject * value ) {

int result;
PyObject * validated;

if ( value == NULL )
return set_delete_property_error( obj, name );

PyObject * validated = traitd->validate( traitd, obj, name, value );
validated = traitd->validate( traitd, obj, name, value );
if ( validated == NULL )
return -1;
result = ((trait_setattr) traitd->post_setattr)( traito, traitd, obj, name,
Expand Down
31 changes: 31 additions & 0 deletions traits/tests/test_property_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Unit tests to ensure that we can call reset_traits/delete on a
property trait (regression tests for Github issue #67).

"""

from traits import _py2to3
from traits.api import Any, HasTraits, Int, Property, TraitError
from traits.testing.unittest_tools import unittest


class E(HasTraits):

a = Property(Any)

b = Property(Int)


class TestPropertyDelete(unittest.TestCase):

def test_property_delete(self):
e = E()
with self.assertRaises(TraitError):
del e.a
with self.assertRaises(TraitError):
del e.b

def test_property_reset_traits(self):
e = E()
unresetable = e.reset_traits()
_py2to3.assertCountEqual(self, unresetable, ['a', 'b'])