Skip to content

Commit

Permalink
Merge pull request #175 from enthought/fix-deprecated-unittest-methods
Browse files Browse the repository at this point in the history
Fix some more uses of deprecated unittest methods.
  • Loading branch information
mdickinson committed Apr 25, 2014
2 parents a14d11e + 39661ae commit 056f421
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 178 deletions.
58 changes: 29 additions & 29 deletions traits/tests/test_clone.py
Expand Up @@ -165,9 +165,9 @@ def test_Any_circular_references(self):

bar_copy = bar.clone_traits()

self.failIf(bar_copy is bar)
self.failUnless(bar_copy.other is baz)
self.failUnless(bar_copy.other.other is bar)
self.assertIsNot(bar_copy, bar)
self.assertIs(bar_copy.other, baz)
self.assertIs(bar_copy.other.other, bar)

def test_Any_circular_references_deep(self):

Expand All @@ -179,10 +179,10 @@ def test_Any_circular_references_deep(self):

bar_copy = bar.clone_traits(copy='deep')

self.failIf(bar_copy is bar)
self.failIf(bar_copy.other is baz)
self.failIf(bar_copy.other.other is bar)
self.failUnless(bar_copy.other.other is bar_copy)
self.assertIsNot(bar_copy, bar)
self.assertIsNot(bar_copy.other, baz)
self.assertIsNot(bar_copy.other.other, bar)
self.assertIs(bar_copy.other.other, bar_copy)

def test_Instance_circular_references(self):

Expand All @@ -207,34 +207,34 @@ def test_Instance_circular_references(self):
baz_copy = baz.clone_traits()

# Check Baz and Baz attributes....
self.failIf(baz_copy is baz)
self.failIf(baz_copy.other is bar)
self.failIf(baz_copy.unique is baz.unique)
self.failIf(baz_copy.shared is baz.shared)
self.failUnless(baz_copy.ref is ref)
self.assertIsNot(baz_copy, baz)
self.assertIsNot(baz_copy.other, bar)
self.assertIsNot(baz_copy.unique, baz.unique)
self.assertIsNot(baz_copy.shared, baz.shared)
self.assertIs(baz_copy.ref, ref)

# Check Bar and Bar attributes....
bar_copy = baz_copy.other

# Check the Bar owned object
self.failIf(bar_copy.unique is bar.unique)
self.assertIsNot(bar_copy.unique, bar.unique)

# Check the Bar reference to an object 'outside' the cloned graph.
self.failUnless(bar_copy.ref is ref)
self.assertIs(bar_copy.ref, ref)

# Check references to objects that where cloned, they should reference
# the new clones not the original objects, except when copy is set
# to 'ref' (as in the case of the 'other' trait).
# When copy is set to ref, the trait does not get cloned. Therefore,
# baz_copy.other.other is baz (and not baz_copy).
self.failIf(bar_copy.other is baz_copy)
self.failUnless(bar_copy.other is baz)
self.assertIsNot(bar_copy.other, baz_copy)
self.assertIs(bar_copy.other, baz)

# 'shared' does not have copy set to 'ref', and so bar_copy.shared
# should reference the new clone.
# should reference the new clones
self.failIf(bar_copy.shared is baz.shared)
self.failUnless(bar_copy.shared is baz_copy.shared)
self.assertIsNot(bar_copy.shared, baz.shared)
self.assertIs(bar_copy.shared, baz_copy.shared)

def test_Instance_circular_references_deep(self):

Expand All @@ -259,37 +259,37 @@ def test_Instance_circular_references_deep(self):
baz_copy = baz.clone_traits(copy='deep')

# Check Baz and Baz attributes....
self.failIf(baz_copy is baz)
self.failIf(baz_copy.other is bar)
self.failIf(baz_copy.unique is baz.unique)
self.failIf(baz_copy.shared is baz.shared)
self.assertIsNot(baz_copy, baz)
self.assertIsNot(baz_copy.other, bar)
self.assertIsNot(baz_copy.unique, baz.unique)
self.assertIsNot(baz_copy.shared, baz.shared)
# baz_copy.ref is checked below with bar_copy.ref.

# Check Bar and Bar attributes....
bar_copy = baz_copy.other

# Check the Bar owned object
self.failIf(bar_copy.unique is bar.unique)
self.assertIsNot(bar_copy.unique, bar.unique)

# Since the two original 'ref' links were to a shared object,
# the cloned links should be to a shared object. Also, the shared
# object should be the original 'ref' object, since copy was set to
# 'ref'.
self.failUnless(baz_copy.ref is bar_copy.ref)
self.failUnless(bar_copy.ref is ref)
self.assertIs(baz_copy.ref, bar_copy.ref)
self.assertIs(bar_copy.ref,ref)

# Check references to objects that where cloned, they should reference
# the new clones not the original objects, except when copy is set
# to 'ref' (as in the case of the 'other' trait). That is, the 'deep'
# flag on clone_traits should not override the 'copy' metadata on
# the trait.
self.failIf(bar_copy.other is baz_copy)
self.failUnless(bar_copy.other is baz)
self.assertIsNot(bar_copy.other, baz_copy)
self.assertIs(bar_copy.other, baz)

# 'shared' does not have copy set to 'ref', and so bar_copy.shared
# should reference the new clone.
self.failIf(bar_copy.shared is baz.shared)
self.failUnless(bar_copy.shared is baz_copy.shared)
self.assertIsNot(bar_copy.shared, baz.shared)
self.assertIs(bar_copy.shared, baz_copy.shared)

#
# support running this test individually, from the command-line as a script
Expand Down
104 changes: 52 additions & 52 deletions traits/tests/test_copy_traits.py
Expand Up @@ -93,86 +93,86 @@ def setUp(self):
return

def test_setup(self):
self.failUnless(self.foo is self.bar.foo)
self.failUnless(self.bar is self.baz.bar)
self.failUnless(self.foo.shared is self.shared)
self.failUnless(self.bar.shared is self.shared)
self.failUnless(self.baz.shared is self.shared)

self.failUnless(self.foo2 is self.bar2.foo)
self.failUnless(self.bar2 is self.baz2.bar)
self.failUnless(self.foo2.shared is self.shared2)
self.failUnless(self.bar2.shared is self.shared2)
self.failUnless(self.baz2.shared is self.shared2)
self.assertIs(self.foo, self.bar.foo)
self.assertIs(self.bar, self.baz.bar)
self.assertIs(self.foo.shared, self.shared)
self.assertIs(self.bar.shared, self.shared)
self.assertIs(self.baz.shared, self.shared)

self.assertIs(self.foo2, self.bar2.foo)
self.assertIs(self.bar2, self.baz2.bar)
self.assertIs(self.foo2.shared, self.shared2)
self.assertIs(self.bar2.shared, self.shared2)
self.assertIs(self.baz2.shared, self.shared2)
return


class CopyTraits:

def test_baz2_s(self):
self.failUnlessEqual(self.baz2.s, 'baz')
self.failUnlessEqual(self.baz2.s, self.baz.s)
self.assertEqual(self.baz2.s, 'baz')
self.assertEqual(self.baz2.s, self.baz.s)

def test_baz2_bar_s(self):
self.failUnlessEqual(self.baz2.bar.s, 'bar')
self.failUnlessEqual(self.baz2.bar.s, self.baz.bar.s)
self.assertEqual(self.baz2.bar.s, 'bar')
self.assertEqual(self.baz2.bar.s, self.baz.bar.s)

def test_baz2_bar_foo_s(self):
self.failUnlessEqual(self.baz2.bar.foo.s, 'foo')
self.failUnlessEqual(self.baz2.bar.foo.s, self.baz.bar.foo.s)
self.assertEqual(self.baz2.bar.foo.s, 'foo')
self.assertEqual(self.baz2.bar.foo.s, self.baz.bar.foo.s)

def test_baz2_shared_s(self):
self.failUnlessEqual(self.baz2.shared.s, 'shared')
self.failUnlessEqual(self.baz2.bar.shared.s, 'shared')
self.failUnlessEqual(self.baz2.bar.foo.shared.s, 'shared')
self.assertEqual(self.baz2.shared.s, 'shared')
self.assertEqual(self.baz2.bar.shared.s, 'shared')
self.assertEqual(self.baz2.bar.foo.shared.s, 'shared')

def test_baz2_bar(self):
# First hand Instance trait is different and
# is not the same object as the source.

self.failIf(self.baz2.bar is None)
self.failIf(self.baz2.bar is self.bar2)
self.failIf(self.baz2.bar is self.baz.bar)
self.assertIsNot(self.baz2.bar, None)
self.assertIsNot(self.baz2.bar, self.bar2)
self.assertIsNot(self.baz2.bar, self.baz.bar)

def test_baz2_bar_foo(self):
# Second hand Instance trait is a different object and
# is not the same object as the source.

self.failIf(self.baz2.bar.foo is None)
self.failIf(self.baz2.bar.foo is self.foo2)
self.failIf(self.baz2.bar.foo is self.baz.bar.foo)
self.assertIsNot(self.baz2.bar.foo, None)
self.assertIsNot(self.baz2.bar.foo, self.foo2)
self.assertIsNot(self.baz2.bar.foo, self.baz.bar.foo)


class CopyTraitsSharedCopyNone:
def test_baz2_shared(self):
# First hand Instance trait is a different object and
# is not the same object as the source.

self.failIf(self.baz2.shared is None)
self.failIf(self.baz2.shared is self.shared2)
self.failIf(self.baz2.shared is self.shared)
self.assertIsNot(self.baz2.shared, None)
self.assertIsNot(self.baz2.shared, self.shared2)
self.assertIsNot(self.baz2.shared, self.shared)

def test_baz2_bar_shared(self):
# Second hand Instance that was shared is a different object and
# not the same object as the source and
# not the same object as the new first hand instance that was the same.
# I.e. There are now (at least) two copies of one original object.

self.failIf(self.baz2.bar.shared is None)
self.failIf(self.baz2.bar.shared is self.shared2)
self.failIf(self.baz2.bar.shared is self.shared)
self.failIf(self.baz2.bar.shared is self.baz2.shared)
self.assertIsNot(self.baz2.bar.shared, None)
self.assertIsNot(self.baz2.bar.shared, self.shared2)
self.assertIsNot(self.baz2.bar.shared, self.shared)
self.assertIsNot(self.baz2.bar.shared, self.baz2.shared)

def test_baz2_bar_foo_shared(self):
# Third hand Instance that was shared is a different object and
# not the same object as the source and
# not the same object as the new first hand instance that was the same.
# I.e. There are now (at least) two copies of one original object.

self.failIf(self.baz2.bar.foo.shared is None)
self.failIf(self.baz2.bar.foo.shared is self.shared2)
self.failIf(self.baz2.bar.foo.shared is self.shared)
self.failIf(self.baz2.bar.foo.shared is self.baz2.shared)
self.assertIsNot(self.baz2.bar.foo.shared, None)
self.assertIsNot(self.baz2.bar.foo.shared, self.shared2)
self.assertIsNot(self.baz2.bar.foo.shared, self.shared)
self.assertIsNot(self.baz2.bar.foo.shared, self.baz2.shared)

def test_baz2_bar_and_foo_shared(self):
#
Expand All @@ -186,8 +186,8 @@ def test_baz2_bar_and_foo_shared(self):
# first hand reference which is a different copy.
# I.e. The shared relationship has been fubarred by copy_traits: it's
# not maintained, but not completely destroyed.
self.failUnless(self.baz2.bar.shared is self.baz2.bar.foo.shared)
self.failIf(self.baz2.shared is self.baz2.bar.foo.shared)
self.assertIs(self.baz2.bar.shared, self.baz2.bar.foo.shared)
self.assertIsNot(self.baz2.shared, self.baz2.bar.foo.shared)


class TestCopyTraitsSharedCopyNone(CopyTraits,
Expand Down Expand Up @@ -245,25 +245,25 @@ def test_baz2_shared(self):
# First hand Instance trait is a different object and
# is the same object as the source.

self.failIf(self.baz2.shared is None)
self.failIf(self.baz2.shared is self.shared2)
self.failUnless(self.baz2.shared is self.shared)
self.assertIsNot(self.baz2.shared, None)
self.assertIsNot(self.baz2.shared, self.shared2)
self.assertIs(self.baz2.shared, self.shared)

def test_baz2_bar_shared(self):
self.failIf(self.baz2.bar.shared is None)
self.failIf(self.baz2.bar.shared is self.shared2)
self.failUnless(self.baz2.bar.shared is self.shared)
self.failUnless(self.baz2.bar.shared is self.baz2.shared)
self.assertIsNot(self.baz2.bar.shared, None)
self.assertIsNot(self.baz2.bar.shared, self.shared2)
self.assertIs(self.baz2.bar.shared, self.shared)
self.assertIs(self.baz2.bar.shared, self.baz2.shared)

def test_baz2_bar_foo_shared(self):
self.failIf(self.baz2.bar.foo.shared is None)
self.failIf(self.baz2.bar.foo.shared is self.shared2)
self.failUnless(self.baz2.bar.foo.shared is self.shared)
self.failUnless(self.baz2.bar.foo.shared is self.baz2.shared)
self.assertIsNot(self.baz2.bar.foo.shared, None)
self.assertIsNot(self.baz2.bar.foo.shared, self.shared2)
self.assertIs(self.baz2.bar.foo.shared, self.shared)
self.assertIs(self.baz2.bar.foo.shared, self.baz2.shared)

def test_baz2_bar_and_foo_shared(self):
self.failUnless(self.baz2.bar.shared is self.baz2.bar.foo.shared)
self.failUnless(self.baz2.shared is self.baz2.bar.foo.shared)
self.assertIs(self.baz2.bar.shared, self.baz2.bar.foo.shared)
self.assertIs(self.baz2.shared, self.baz2.bar.foo.shared)


class TestCopyTraitsSharedCopyRef(CopyTraits,
Expand Down
10 changes: 5 additions & 5 deletions traits/tests/test_copyable_trait_names.py
Expand Up @@ -53,13 +53,13 @@ def setUp(self):
self.names = foo.copyable_trait_names()

def test_events_not_copyable(self):
self.failIf('e' in self.names)
self.assertNotIn('e', self.names)

def test_read_only_property_not_copyable(self):
self.failIf('p_ro' in self.names)
self.assertNotIn('p_ro', self.names)

def test_write_only_property_not_copyable(self):
self.failIf('p_wo' in self.names)
self.assertNotIn('p_wo', self.names)

def test_any_copyable(self):
self.assertIn('a', self.names)
Expand Down Expand Up @@ -90,13 +90,13 @@ def test_type_query(self):
'type': 'trait'
})

self.failUnlessEqual(['a', 'b', 'i', 's'], sorted(names))
self.assertEqual(['a', 'b', 'i', 's'], sorted(names))

names = self.foo.copyable_trait_names(**{
'type': lambda t: t in ('trait', 'property',)
})

self.failUnlessEqual(['a', 'b', 'i', 'p', 's'], sorted(names))
self.assertEqual(['a', 'b', 'i', 'p', 's'], sorted(names))

def test_property_query(self):
names = self.foo.copyable_trait_names(**{
Expand Down
4 changes: 2 additions & 2 deletions traits/tests/test_event_order.py
Expand Up @@ -35,15 +35,15 @@ def test_lifo_order(self):
'Baz._effect_changed',
'Baz._caused_changed']

self.failUnlessEqual(self.events_delivered, lifo)
self.assertEqual(self.events_delivered, lifo)
return

def test_not_fifo_order(self):
fifo = ['Bar._caused_changed',
'Baz._caused_changed',
'Baz._effect_changed']

self.failIfEqual(self.events_delivered, fifo)
self.assertNotEqual(self.events_delivered, fifo)
return


Expand Down

0 comments on commit 056f421

Please sign in to comment.