Skip to content

Commit

Permalink
Merge pull request #173 from enthought/test-assert-eventually-true
Browse files Browse the repository at this point in the history
Add basic tests for assertEventuallyTrue.
  • Loading branch information
itziakos committed Apr 22, 2014
2 parents 365315f + f209395 commit a14d11e
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion traits/testing/tests/test_unittest_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#------------------------------------------------------------------------------
import threading
import time
import sys

from traits import _py2to3

Expand Down Expand Up @@ -306,6 +305,61 @@ def thread_target(obj, count):
for t in threads:
t.join()

def test_assert_eventually_true_fails_on_timeout(self):
class A(HasTraits):
foo = Bool(False)

a = A()

def condition(a_object):
return a_object.foo

with self.assertRaises(self.failureException):
self.assertEventuallyTrue(
condition=condition,
obj=a,
trait='foo',
timeout=1.0,
)

def test_assert_eventually_true_passes_when_condition_becomes_true(self):
class A(HasTraits):
foo = Bool(False)

def condition(a_object):
return a_object.foo

a = A()

def thread_target(a):
time.sleep(1.0)
a.foo = True

t = threading.Thread(target=thread_target, args=(a,))
t.start()
self.assertEventuallyTrue(
condition=condition,
obj=a,
trait='foo',
timeout=10.0,
)
t.join()

def test_assert_eventually_true_passes_when_condition_starts_true(self):
class A(HasTraits):
foo = Bool(True)

def condition(a_object):
return a_object.foo

a = A()
self.assertEventuallyTrue(
condition=condition,
obj=a,
trait='foo',
timeout=10.0,
)


if __name__ == '__main__':
unittest.main()

0 comments on commit a14d11e

Please sign in to comment.