Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Future-proof test methods: failUnless*() --> assert*().

In Python 2.7 and Python 3.x, the unittest2 module deprecates the
failUnless* method names. So this is a preemptive change to use the
assert* versions of the names, even thought I find them less naturally
descriptive.
  • Loading branch information...
commit f3565bbaa877f92b9b6f638a9f67d8c777177ce8 1 parent c3d9caf
@malcolmt authored
Showing with 41 additions and 41 deletions.
  1. +26 −26 acacia/tests/test_models.py
  2. +15 −15 acacia/tests/test_templatetags.py
View
52 acacia/tests/test_models.py
@@ -90,7 +90,7 @@ def test_get_by_full_name3(self):
"""
# Use "c" as the test here, since there's more than one Topic instance
# with a name of "c", but only one topic whose full name is "c".
- self.failUnless(models.Topic.objects.filter(name="c").count() > 1)
+ self.assertTrue(models.Topic.objects.filter(name="c").count() > 1)
node = models.Topic.objects.get_by_full_name("c")
self.assertEquals(unicode(node), u"c")
@@ -161,10 +161,10 @@ def test_simple_merge_nodes(self):
signals.pre_merge.connect(self.signal_catcher)
node.merge_to(target)
signals.pre_merge.disconnect(self.signal_catcher)
- self.failUnlessEqual(len(self.signals), 1)
+ self.assertEqual(len(self.signals), 1)
merge_pairs = self.signals[0][1]["merge_pairs"]
- self.failUnlessEqual(len(merge_pairs), 1)
- self.failUnlessEqual(merge_pairs[0], (old_id, surviving_node.id))
+ self.assertEqual(len(merge_pairs), 1)
+ self.assertEqual(merge_pairs[0], (old_id, surviving_node.id))
def test_multiple_merge_nodes(self):
"""
@@ -179,11 +179,11 @@ def test_multiple_merge_nodes(self):
signals.pre_merge.connect(self.signal_catcher)
node.merge_to(target)
signals.pre_merge.disconnect(self.signal_catcher)
- self.failUnlessEqual(len(self.signals), 1)
+ self.assertEqual(len(self.signals), 1)
merge_pairs = self.signals[0][1]["merge_pairs"]
- self.failUnlessEqual(len(merge_pairs), 2)
- self.failUnlessEqual(merge_pairs[0], (old_ids[0], pivot.parent_id))
- self.failUnlessEqual(merge_pairs[1], (old_ids[1], pivot.id))
+ self.assertEqual(len(merge_pairs), 2)
+ self.assertEqual(merge_pairs[0], (old_ids[0], pivot.parent_id))
+ self.assertEqual(merge_pairs[1], (old_ids[1], pivot.id))
try:
models.Topic.objects.get_by_full_name("a/x/y/c")
except models.Topic.DoesNotExist:
@@ -200,18 +200,18 @@ def test_merge_without_overlap(self):
signals.pre_move.connect(self.signal_catcher)
node.merge_to(target)
signals.pre_merge.disconnect(self.signal_catcher)
- self.failUnlessEqual(len(self.signals), 1)
+ self.assertEqual(len(self.signals), 1)
signal_dict = self.signals[0][1]
- self.failUnlessEqual(signal_dict["signal"], signals.pre_move)
- self.failUnlessEqual(signal_dict["moving"][0][0].id, node.id)
- self.failUnlessEqual(signal_dict["moving"][0][1].id, target.id)
+ self.assertEqual(signal_dict["signal"], signals.pre_move)
+ self.assertEqual(signal_dict["moving"][0][0].id, node.id)
+ self.assertEqual(signal_dict["moving"][0][1].id, target.id)
try:
models.Topic.objects.get_by_full_name("a/d")
except models.Topic.DoesNotExist:
self.fail("Node wasn't moved to correct location.")
- self.failUnlessRaises(models.Topic.DoesNotExist,
+ self.assertRaises(models.Topic.DoesNotExist,
models.Topic.objects.get_by_full_name, "c/b/d")
- self.failUnlessRaises(models.Topic.DoesNotExist,
+ self.assertRaises(models.Topic.DoesNotExist,
models.Topic.objects.get_by_full_name, "c/b/d/e")
def test_merge_moves_all_subtrees(self):
@@ -225,18 +225,18 @@ def test_merge_moves_all_subtrees(self):
node = models.Topic.objects.get_by_full_name("x")
y_child = models.Topic.objects.get_by_full_name("x/y")
node.merge_to(parent)
- self.failUnlessRaises(models.Topic.DoesNotExist,
+ self.assertRaises(models.Topic.DoesNotExist,
models.Topic.objects.get_by_full_name, "x")
try:
node = models.Topic.objects.get_by_full_name("a/x/c/z")
except models.Topic.DoesNotExist:
self.fail("Didn't move x/c/z node correctly.")
- self.failUnlessEqual(node.id, z_child.id)
+ self.assertEqual(node.id, z_child.id)
try:
node = models.Topic.objects.get_by_full_name("a/x/y")
except models.Topic.DoesNotExist:
self.fail("Didn't move x/y node correctly.")
- self.failUnlessEqual(node.id, y_child.id)
+ self.assertEqual(node.id, y_child.id)
def test_move_is_not_merge(self):
"""
@@ -245,7 +245,7 @@ def test_move_is_not_merge(self):
"""
target = models.Topic.objects.get_by_full_name("a")
node = models.Topic.objects.get_by_full_name("x")
- self.failUnlessRaises(db.IntegrityError, node.move_to, target)
+ self.assertRaises(db.IntegrityError, node.move_to, target)
def test_create_by_full_name1(self):
"""
@@ -253,9 +253,9 @@ def test_create_by_full_name1(self):
full name works.
"""
_, created = models.Topic.objects.get_or_create_by_full_name("a/b")
- self.failUnlessEqual(created, False)
+ self.assertEqual(created, False)
_, created = models.Topic.objects.get_or_create_by_full_name("a/b/e")
- self.failUnlessEqual(created, True)
+ self.assertEqual(created, True)
def test_create_by_full_name2(self):
"""
@@ -263,9 +263,9 @@ def test_create_by_full_name2(self):
works.
"""
_, created = models.Topic.objects.get_or_create_by_full_name("a/z/z")
- self.failUnlessEqual(created, True)
+ self.assertEqual(created, True)
node = models.Topic.objects.get_by_full_name("a/z/z")
- self.failUnlessEqual(unicode(node), u"a/z/z")
+ self.assertEqual(unicode(node), u"a/z/z")
def test_create_by_full_name3(self):
"""
@@ -274,7 +274,7 @@ def test_create_by_full_name3(self):
nothing new is created).
"""
_, created = models.Topic.objects.get_or_create_by_full_name("c/b/d")
- self.failUnlessEqual(created, False)
+ self.assertEqual(created, False)
def test_create_by_full_name4(self):
"""
@@ -284,15 +284,15 @@ def test_create_by_full_name4(self):
"""
node, created = models.Topic.objects.get_or_create_by_full_name(
"a///b/e//")
- self.failUnlessEqual(created, True)
- self.failUnlessEqual(unicode(node), u"a/b/e")
+ self.assertEqual(created, True)
+ self.assertEqual(unicode(node), u"a/b/e")
def test_create_by_full_name5(self):
"""
Tests that creating a new node with a new root works as expected.
"""
_, created = models.Topic.objects.get_or_create_by_full_name("j/k/l")
- self.failUnlessEqual(created, True)
+ self.assertEqual(created, True)
def test_create_duplicate_entry(self):
"""
View
30 acacia/tests/test_templatetags.py
@@ -21,31 +21,31 @@ def convert(template_string):
class TreeTrunkErrorTests(test.TestCase):
def test_invalid_app_name(self):
- self.failUnlessRaises(template.TemplateSyntaxError, convert,
+ self.assertRaises(template.TemplateSyntaxError, convert,
"{% load acacia %}{% treetrunk bad.Topic %}")
def test_invalid_model_name(self):
- self.failUnlessRaises(template.TemplateSyntaxError, convert,
+ self.assertRaises(template.TemplateSyntaxError, convert,
"{% load acacia %}{% treetrunk acacia.BadName %}")
def test_non_integer_level_value(self):
- self.failUnlessRaises(template.TemplateSyntaxError, convert,
+ self.assertRaises(template.TemplateSyntaxError, convert,
"{% load acacia %}{% treetrunk acacia.Topic bad %}")
def test_negative_level_value(self):
- self.failUnlessRaises(template.TemplateSyntaxError, convert,
+ self.assertRaises(template.TemplateSyntaxError, convert,
"{% load acacia %}{% treetrunk acacia.Topic -1 %}")
def test_zero_level_value(self):
- self.failUnlessRaises(template.TemplateSyntaxError, convert,
+ self.assertRaises(template.TemplateSyntaxError, convert,
"{% load acacia %}{% treetrunk acacia.Topic 0 %}")
def test_too_many_arguments(self):
- self.failUnlessRaises(template.TemplateSyntaxError, convert,
+ self.assertRaises(template.TemplateSyntaxError, convert,
"{% load acacia %}{% treetrunk acacia.Topic 2 extra %}")
def test_too_few_arguments(self):
- self.failUnlessRaises(template.TemplateSyntaxError, convert,
+ self.assertRaises(template.TemplateSyntaxError, convert,
"{% load acacia %}{% treetrunk %}")
@@ -68,7 +68,7 @@ def test_html_sensitive_content(self):
<ul><li>&lt;</li></ul>
</li></ul>
</li></ul>""".replace("\n", "").replace(" ", "")
- self.failUnlessEqual(output, expected, "\nGot %s\n\nExpected %s" %
+ self.assertEqual(output, expected, "\nGot %s\n\nExpected %s" %
(output, expected))
@@ -90,7 +90,7 @@ def test_single_level(self):
<ul>
<li>root1</li>
</ul>""".replace("\n", "").replace(" ", "")
- self.failUnlessEqual(output, expected, "\nGot %s\n\nExpected %s" %
+ self.assertEqual(output, expected, "\nGot %s\n\nExpected %s" %
(output, expected))
def test_two_levels(self):
@@ -104,7 +104,7 @@ def test_two_levels(self):
<li>child3</li>
</ul></li>
</ul>""".replace("\n", "").replace(" ", "")
- self.failUnlessEqual(output, expected, "\nGot %s\n\nExpected %s" %
+ self.assertEqual(output, expected, "\nGot %s\n\nExpected %s" %
(output, expected))
def test_three_levels(self):
@@ -123,7 +123,7 @@ def test_three_levels(self):
<ul><li>grandchild1</li></ul></li>
</ul></li>
</ul>""".replace("\n", "").replace(" ", "")
- self.failUnlessEqual(output, expected, "\nGot %s\n\nExpected %s" %
+ self.assertEqual(output, expected, "\nGot %s\n\nExpected %s" %
(output, expected))
def test_more_levels_than_nodes(self):
@@ -142,7 +142,7 @@ def test_more_levels_than_nodes(self):
<ul><li>grandchild1</li></ul></li>
</ul></li>
</ul>""".replace("\n", "").replace(" ", "")
- self.failUnlessEqual(output, expected, "\nGot %s\n\nExpected %s" %
+ self.assertEqual(output, expected, "\nGot %s\n\nExpected %s" %
(output, expected))
def test_default_level(self):
@@ -156,7 +156,7 @@ def test_default_level(self):
<li>child3</li>
</ul></li>
</ul>""".replace("\n", "").replace(" ", "")
- self.failUnlessEqual(output, expected, "\nGot %s\n\nExpected %s" %
+ self.assertEqual(output, expected, "\nGot %s\n\nExpected %s" %
(output, expected))
@@ -186,7 +186,7 @@ def test_one_level(self):
<li>root2</li>
<li>root3</li>
</ul>""".replace("\n", "").replace(" ", "")
- self.failUnlessEqual(output, expected, "\nGot %s\n\nExpected %s" %
+ self.assertEqual(output, expected, "\nGot %s\n\nExpected %s" %
(output, expected))
def test_three_levels(self):
@@ -215,6 +215,6 @@ def test_three_levels(self):
</ul></li>
<li>root3</li>
</ul>""".replace("\n", "").replace(" ", "")
- self.failUnlessEqual(output, expected, "\nGot %s\n\nExpected %s" %
+ self.assertEqual(output, expected, "\nGot %s\n\nExpected %s" %
(output, expected))
Please sign in to comment.
Something went wrong with that request. Please try again.