Skip to content

Commit

Permalink
Merge pull request #138 from enthought/fix-issue-67-ctraits
Browse files Browse the repository at this point in the history
Check for property deletion (#67)
  • Loading branch information
mdickinson committed Feb 25, 2014
2 parents eb6a4da + cfcf87a commit 3144ea6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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'])

0 comments on commit 3144ea6

Please sign in to comment.