Skip to content

Commit

Permalink
Merge pull request enthought#58 from enthought/fix-issue-57
Browse files Browse the repository at this point in the history
Fix issue 57
  • Loading branch information
itziakos committed Feb 27, 2014
2 parents 7dd4d84 + e7c6cc8 commit e5323d4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
68 changes: 65 additions & 3 deletions traits_enaml/tests/test_trait_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
#----------------------------------------------------------------------------
import unittest

from traits.api import Event, HasTraits, Str, List, Dict, Set
from traits.api import (
Event, Float, HasTraits, Str, List, Dict, Set, Property)
from traits_enaml.testing.enaml_test_assistant import EnamlTestAssistant


class TraitModel(HasTraits):
value = Float
value_delegate = Str()
value_subscribe = Str()
value_update = Str()
Expand All @@ -26,6 +28,19 @@ class TraitModel(HasTraits):
list_values = List(Str)
dict_values = Dict(Str, Str)
set_values = Set(Str)
property_value = Property(depends_on='value')
typed_property_value = Property(Float, depends_on='value')
collection_property_value = Property(List, depends_on='value')

def _get_property_value(self):
return self.value

def _get_typed_property_value(self):
return self.value

def _get_collection_property_value(self):
value = self.value
return [value, value * 10]


class TraitOperatorsTestCase(EnamlTestAssistant, unittest.TestCase):
Expand Down Expand Up @@ -64,6 +79,15 @@ def setUp(self):
Field:
name = 'test_set_subscribe'
text << str(model.set_values)
Field:
name = 'test_property_subscribe'
text << str(model.property_value)
Field:
name = 'test_typed_property_subscribe'
text << str(model.typed_property_value)
Field:
name = 'test_collection_property_subscribe'
text << str(model.collection_property_value)
"""
self.model = TraitModel()
view, toolkit_view = self.parse_and_create(
Expand Down Expand Up @@ -168,7 +192,7 @@ def test_dict_subscribe(self):

enaml_widget = self.view.find('test_dict_subscribe')

with self.assertTraitDoesNotChange(self.model, 'list_values'):
with self.assertTraitDoesNotChange(self.model, 'dict_values'):
enaml_widget.text = 'new_value'

# check on replace
Expand All @@ -191,7 +215,7 @@ def test_set_subscribe(self):

enaml_widget = self.view.find('test_set_subscribe')

with self.assertTraitDoesNotChange(self.model, 'list_values'):
with self.assertTraitDoesNotChange(self.model, 'set_values'):
enaml_widget.text = 'new_value'

# check on replace
Expand All @@ -208,3 +232,41 @@ def test_set_subscribe(self):
with self.assertAtomChanges(enaml_widget, 'text', count=1):
self.model.set_values.remove('1')
self.assertEquals(enaml_widget.text, "TraitSetObject(['2'])")

def test_property_subscribe(self):

enaml_widget = self.view.find('test_property_subscribe')

with self.assertTraitDoesNotChange(self.model, 'property_value'):
enaml_widget.text = 'new_value'

# check on replace
with self.assertAtomChanges(enaml_widget, 'text', count=1):
self.model.value = 3.4
self.assertEquals(enaml_widget.text, u"3.4")

def test_typed_property_subscribe(self):

enaml_widget = self.view.find('test_typed_property_subscribe')

with self.assertTraitDoesNotChange(
self.model, 'typed_property_value'):
enaml_widget.text = 'new_value'

# check on replace
with self.assertAtomChanges(enaml_widget, 'text', count=1):
self.model.value = 4.5
self.assertEquals(enaml_widget.text, u"4.5")

def test_collection_property_subscribe(self):

enaml_widget = self.view.find('test_collection_property_subscribe')

with self.assertTraitDoesNotChange(
self.model, 'collection_property_value'):
enaml_widget.text = 'new_value'

# check on replace
with self.assertAtomChanges(enaml_widget, 'text', count=1):
self.model.value = 4.5
self.assertEquals(enaml_widget.text, u"[4.5, 45.0]")
2 changes: 1 addition & 1 deletion traits_enaml/traits_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _trace_trait(self, obj, name):
if trait is not None and trait.trait_type is not Disallow:
self.traced_traits.add((obj, name))
# Check for collections.
if trait.handler.has_items:
if trait.handler is not None and trait.handler.has_items:
self.traced_traits.add((obj, '{}_items'.format(name)))

#--------------------------------------------------------------------------
Expand Down

0 comments on commit e5323d4

Please sign in to comment.