From 5a61600bc9948c318ccad79943df2f51756adcd8 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 12 Jun 2013 14:52:23 -0400 Subject: [PATCH] tests: Avoid hidden logic with better .assert*() method choices We'll get better failure messages if we use an assertion method that understands the comparison we're trying to make. If you make the comparison by hand and assertTrue(), you don't get much constructive feedback ;). --- pelican/tests/test_generators.py | 4 ++-- pelican/tests/test_importer.py | 4 ++-- pelican/tests/test_utils.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pelican/tests/test_generators.py b/pelican/tests/test_generators.py index e3b8e20a..48aff498 100644 --- a/pelican/tests/test_generators.py +++ b/pelican/tests/test_generators.py @@ -108,7 +108,7 @@ class TestArticlesGenerator(unittest.TestCase): sorted(['Default', 'TestCategory', 'Yeah', 'test', '指導書']), sorted(['Default', 'TestCategory', 'yeah', 'test', '指導書']), ) - self.assertTrue(sorted(categories) in categories_alternatives) + self.assertIn(sorted(categories), categories_alternatives) # test for slug categories = [cat.slug for cat, _ in generator.categories] categories_expected = ['default', 'testcategory', 'yeah', 'test', @@ -136,7 +136,7 @@ class TestArticlesGenerator(unittest.TestCase): sorted(['Default', 'Yeah', 'test', '指導書']), sorted(['Default', 'yeah', 'test', '指導書']), ) - self.assertTrue(sorted(categories) in categories_alternatives) + self.assertIn(sorted(categories), categories_alternatives) # test for slug categories = [cat.slug for cat, _ in generator.categories] categories_expected = ['default', 'yeah', 'test', 'zhi-dao-shu'] diff --git a/pelican/tests/test_importer.py b/pelican/tests/test_importer.py index cb095426..53809e7e 100644 --- a/pelican/tests/test_importer.py +++ b/pelican/tests/test_importer.py @@ -76,13 +76,13 @@ class TestWordpressXmlImporter(unittest.TestCase): def test_decode_html_entities_in_titles(self): test_posts = [post for post in self.posts if post[2] == 'html-entity-test'] - self.assertTrue(len(test_posts) == 1) + self.assertEqual(len(test_posts), 1) post = test_posts[0] title = post[0] self.assertTrue(title, "A normal post with some entities in the" " title. You can't miss them.") - self.assertTrue('&' not in title) + self.assertNotIn('&', title) def test_decode_wp_content_returns_empty(self): """ Check that given an empty string we return an empty string.""" diff --git a/pelican/tests/test_utils.py b/pelican/tests/test_utils.py index 8b0dc13e..1d538ca0 100644 --- a/pelican/tests/test_utils.py +++ b/pelican/tests/test_utils.py @@ -186,7 +186,7 @@ class TestUtils(LoggedTestCase): test_directory = os.path.join(os.path.dirname(__file__), 'does_not_exist') utils.clean_output_dir(test_directory) - self.assertTrue(not os.path.exists(test_directory)) + self.assertFalse(os.path.exists(test_directory)) def test_clean_output_dir_is_file(self): test_directory = os.path.join(os.path.dirname(__file__), @@ -195,7 +195,7 @@ class TestUtils(LoggedTestCase): f.write('') f.close() utils.clean_output_dir(test_directory) - self.assertTrue(not os.path.exists(test_directory)) + self.assertFalse(os.path.exists(test_directory)) def test_strftime(self): d = datetime.date(2012, 8, 29)