Skip to content

Commit

Permalink
Merge 6746299 into 1f18668
Browse files Browse the repository at this point in the history
  • Loading branch information
itziakos committed Jan 16, 2017
2 parents 1f18668 + 6746299 commit e3535f6
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions traits/testing/unittest_tools.py
Expand Up @@ -18,16 +18,16 @@
import sys
import warnings

from traits.api import (Any, Event, HasStrictTraits, Instance, Int, List,
Property, Str)
from traits.api import (
Any, Event, HasStrictTraits, Instance, Int, List, Str, Property)
from traits.util.async_trait_wait import wait_for_condition

# Compatibility layer for Python 2.6: try loading unittest2
from traits import _py2to3
if sys.version_info[:2] == (2, 6):
import unittest2 as unittest
else:
import unittest
import unittest # noqa


class _AssertTraitChangesContext(object):
Expand Down Expand Up @@ -141,7 +141,7 @@ class _TraitsChangeCollector(HasStrictTraits):
obj = Any

# The (possibly extended) trait name.
trait = Str
monitor_traits = Str

# Read-only event count.
event_count = Property(Int)
Expand All @@ -156,16 +156,26 @@ class _TraitsChangeCollector(HasStrictTraits):
# simultaneously.
_lock = Instance(threading.Lock, ())

def __init__(self, **traits):
value = traits.pop('trait', None)
if value is not None:
message = (
"The `trait` keyword is deprecated."
" please use `monitor_traits`")
warnings.warn(message, DeprecationWarning, stacklevel=2)
traits['monitor_traits'] = value
super(_TraitsChangeCollector, self).__init__(**traits)

def start_collecting(self):
self.obj.on_trait_change(
self._event_handler,
self.trait,
self.monitor_traits,
)

def stop_collecting(self):
self.obj.on_trait_change(
self._event_handler,
self.trait,
self.monitor_traits,
remove=True,
)

Expand Down Expand Up @@ -377,7 +387,7 @@ def assertTraitChangesAsync(self, obj, trait, count=1, timeout=5.0):
of changes. None can be used to indicate no timeout.
"""
collector = _TraitsChangeCollector(obj=obj, trait=trait)
collector = _TraitsChangeCollector(obj=obj, monitor_traits=trait)

# Pass control to body of the with statement.
collector.start_collecting()
Expand Down

0 comments on commit e3535f6

Please sign in to comment.