Skip to content

Commit

Permalink
BUG: Use an existing omnipresent trait for the spring dummy.
Browse files Browse the repository at this point in the history
Fixes #514
  • Loading branch information
rkern committed Mar 11, 2019
1 parent 8516cb0 commit 83630f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 5 additions & 1 deletion traitsui/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,11 @@ class Spring(Item):
#-------------------------------------------------------------------------

# Name of the trait the item is editing
name = 'spring'
# Just a dummy trait that exists on all HasTraits objects. It's an Event,
# so it won't cause Traits UI to add any synchronization, and because it
# already exists, it won't force the addition of a new trait with a bogus
# name.
name = 'trait_modified'

# Should a label be displayed?
show_label = Bool(False)
Expand Down
23 changes: 21 additions & 2 deletions traitsui/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from __future__ import absolute_import
import nose

from traits.has_traits import HasTraits
from traits.has_traits import HasTraits, HasStrictTraits
from traits.trait_types import Str, Int
import traitsui
from traitsui.item import Item
from traitsui.item import Item, spring
from traitsui.view import View

from traitsui.tests._tools import *
Expand All @@ -42,6 +42,17 @@ class FooDialog(HasTraits):
)


class DisallowNewTraits(HasStrictTraits):
""" Make sure no extra traits are added.
"""
x = Int(10)

traits_view = View(
Item('x'),
spring,
)


@skip_if_not_wx
def test_reset_with_destroy_wx():
# Characterization test:
Expand Down Expand Up @@ -191,3 +202,11 @@ def test_destroy_after_ok_qt():

nose.tools.assert_is_none(ui.control)
nose.tools.assert_equal(control.deleteLater._n_calls, 1)


def test_no_spring_trait():
obj = DisallowNewTraits()
ui = obj.edit_traits()
ui.dispose()

nose.tools.assert_true('spring' not in obj.traits())

0 comments on commit 83630f3

Please sign in to comment.