Commit 09f86527 authored by Marc Tamlyn's avatar Marc Tamlyn
Browse files

Use assertIsInstance in tests.

Gives much nicer errors when it fails.
parent 18856f86
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1995,7 +1995,7 @@ class AdminViewListEditable(TestCase):
        }
        response = self.client.post('/test_admin/admin/admin_views/person/', data)
        non_form_errors = response.context['cl'].formset.non_form_errors()
        self.assertTrue(isinstance(non_form_errors, ErrorList))
        self.assertIsInstance(non_form_errors, ErrorList)
        self.assertEqual(str(non_form_errors), str(ErrorList(["Grace is not a Zombie"])))

    def test_list_editable_ordering(self):
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ class LastExecutedQueryTest(TestCase):
        sql, params = persons.query.sql_with_params()
        cursor = persons.query.get_compiler('default').execute_sql(None)
        last_sql = cursor.db.ops.last_executed_query(cursor, sql, params)
        self.assertTrue(isinstance(last_sql, six.text_type))
        self.assertIsInstance(last_sql, six.text_type)

    @unittest.skipUnless(connection.vendor == 'sqlite',
                         "This test is specific to SQLite.")
+5 −5
Original line number Diff line number Diff line
@@ -432,7 +432,7 @@ class ModelTest(TestCase):
            Article.objects.all()[0:-5]
        except Exception as e:
            error = e
        self.assertTrue(isinstance(error, AssertionError))
        self.assertIsInstance(error, AssertionError)
        self.assertEqual(str(error), "Negative indexing is not supported.")

        # An Article instance doesn't have access to the "objects" attribute.
@@ -637,15 +637,15 @@ class ModelTest(TestCase):
        # Can't be instantiated
        with self.assertRaises(TypeError):
            EmptyQuerySet()
        self.assertTrue(isinstance(Article.objects.none(), EmptyQuerySet))
        self.assertIsInstance(Article.objects.none(), EmptyQuerySet)

    def test_emptyqs_values(self):
        # test for #15959
        Article.objects.create(headline='foo', pub_date=datetime.now())
        with self.assertNumQueries(0):
            qs = Article.objects.none().values_list('pk')
            self.assertTrue(isinstance(qs, EmptyQuerySet))
            self.assertTrue(isinstance(qs, ValuesListQuerySet))
            self.assertIsInstance(qs, EmptyQuerySet)
            self.assertIsInstance(qs, ValuesListQuerySet)
            self.assertEqual(len(qs), 0)

    def test_emptyqs_customqs(self):
@@ -660,7 +660,7 @@ class ModelTest(TestCase):
        qs = qs.none()
        with self.assertNumQueries(0):
            self.assertEqual(len(qs), 0)
            self.assertTrue(isinstance(qs, EmptyQuerySet))
            self.assertIsInstance(qs, EmptyQuerySet)
            self.assertEqual(qs.do_something(), 'did something')

    def test_emptyqs_values_order(self):
+4 −4
Original line number Diff line number Diff line
@@ -510,13 +510,13 @@ class BaseCacheTests(object):
                # memcached does not allow whitespace or control characters in keys
                self.cache.set('key with spaces', 'value')
                self.assertEqual(len(w), 2)
                self.assertTrue(isinstance(w[0].message, CacheKeyWarning))
                self.assertIsInstance(w[0].message, CacheKeyWarning)
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")
                # memcached limits key length to 250
                self.cache.set('a' * 251, 'value')
                self.assertEqual(len(w), 1)
                self.assertTrue(isinstance(w[0].message, CacheKeyWarning))
                self.assertIsInstance(w[0].message, CacheKeyWarning)
        finally:
            self.cache.key_func = old_func

@@ -1097,10 +1097,10 @@ class GetCacheTests(unittest.TestCase):
    def test_simple(self):
        cache = get_cache('locmem://')
        from django.core.cache.backends.locmem import LocMemCache
        self.assertTrue(isinstance(cache, LocMemCache))
        self.assertIsInstance(cache, LocMemCache)

        from django.core.cache import cache
        self.assertTrue(isinstance(cache, get_cache('default').__class__))
        self.assertIsInstance(cache, get_cache('default').__class__)

        cache = get_cache(
            'django.core.cache.backends.dummy.DummyCache', **{'TIMEOUT': 120})
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ class CommentFormTests(CommentTestCase):
    def testGetCommentObject(self):
        f = self.testValidPost()
        c = f.get_comment_object()
        self.assertTrue(isinstance(c, Comment))
        self.assertIsInstance(c, Comment)
        self.assertEqual(c.content_object, Article.objects.get(pk=1))
        self.assertEqual(c.comment, "This is my comment")
        c.save()
Loading