Commit 292322f9 authored by Alex Gaynor's avatar Alex Gaynor
Browse files

[py3k] Silence many warnings while running the tests.

parent 4321ee25
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
from django.conf import settings
from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable,
    UserManager)
from django.test import TestCase
from django.test.utils import override_settings
from django.contrib.auth.models import (Group, User,
    SiteProfileNotAvailable, UserManager)
from django.utils import six


@override_settings(USE_TZ=False, AUTH_PROFILE_MODULE='')
@@ -13,19 +14,19 @@ class ProfileTestCase(TestCase):

        # calling get_profile without AUTH_PROFILE_MODULE set
        del settings.AUTH_PROFILE_MODULE
        with self.assertRaisesRegexp(SiteProfileNotAvailable,
        with six.assertRaisesRegex(self, SiteProfileNotAvailable,
                "You need to set AUTH_PROFILE_MODULE in your project"):
            user.get_profile()

        # Bad syntax in AUTH_PROFILE_MODULE:
        settings.AUTH_PROFILE_MODULE = 'foobar'
        with self.assertRaisesRegexp(SiteProfileNotAvailable,
        with six.assertRaisesRegex(self, SiteProfileNotAvailable,
                "app_label and model_name should be separated by a dot"):
            user.get_profile()

        # module that doesn't exist
        settings.AUTH_PROFILE_MODULE = 'foo.bar'
        with self.assertRaisesRegexp(SiteProfileNotAvailable,
        with six.assertRaisesRegex(self, SiteProfileNotAvailable,
                "Unable to load the profile model"):
            user.get_profile()

+1 −1
Original line number Diff line number Diff line
@@ -358,7 +358,7 @@ class SimpleTestCase(ut2.TestCase):
            args: Extra args.
            kwargs: Extra kwargs.
        """
        return self.assertRaisesRegexp(expected_exception,
        return six.assertRaisesRegex(self, expected_exception,
                re.escape(expected_message), callable_obj, *args, **kwargs)

    def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
+7 −0
Original line number Diff line number Diff line
@@ -370,13 +370,20 @@ def with_metaclass(meta, base=object):

if PY3:
    _iterlists = "lists"
    _assertRaisesRegex = "assertRaisesRegex"
else:
    _iterlists = "iterlists"
    _assertRaisesRegex = "assertRaisesRegexp"


def iterlists(d):
    """Return an iterator over the values of a MultiValueDict."""
    return getattr(d, _iterlists)()


def assertRaisesRegex(self, *args, **kwargs):
    return getattr(self, _assertRaisesRegex)(*args, **kwargs)


add_move(MovedModule("_dummy_thread", "dummy_thread"))
add_move(MovedModule("_thread", "thread"))
+14 −14
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ from datetime import datetime
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.fields import Field, FieldDoesNotExist
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.utils.six import PY3
from django.utils import six
from django.utils.translation import ugettext_lazy

from .models import Article
@@ -82,7 +82,7 @@ class ModelTest(TestCase):

        # Django raises an Article.DoesNotExist exception for get() if the
        # parameters don't match any object.
        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            ObjectDoesNotExist,
            "Article matching query does not exist. Lookup parameters were "
            "{'id__exact': 2000}",
@@ -91,14 +91,14 @@ class ModelTest(TestCase):
        )
        # To avoid dict-ordering related errors check only one lookup
        # in single assert.
        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            ObjectDoesNotExist,
            ".*'pub_date__year': 2005.*",
            Article.objects.get,
            pub_date__year=2005,
            pub_date__month=8,
        )
        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            ObjectDoesNotExist,
            ".*'pub_date__month': 8.*",
            Article.objects.get,
@@ -106,7 +106,7 @@ class ModelTest(TestCase):
            pub_date__month=8,
        )

        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            ObjectDoesNotExist,
            "Article matching query does not exist. Lookup parameters were "
            "{'pub_date__week_day': 6}",
@@ -168,7 +168,7 @@ class ModelTest(TestCase):
        self.assertEqual(a4.headline, 'Fourth article')

        # Don't use invalid keyword arguments.
        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            TypeError,
            "'foo' is an invalid keyword argument for this function",
            Article,
@@ -259,13 +259,13 @@ class ModelTest(TestCase):
             "datetime.datetime(2005, 7, 28, 0, 0)"])

        # dates() requires valid arguments.
        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            TypeError,
            "dates\(\) takes at least 3 arguments \(1 given\)",
            Article.objects.dates,
        )

        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            FieldDoesNotExist,
            "Article has no field named 'invalid_field'",
            Article.objects.dates,
@@ -273,7 +273,7 @@ class ModelTest(TestCase):
            "year",
        )

        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            AssertionError,
            "'kind' must be one of 'year', 'month' or 'day'.",
            Article.objects.dates,
@@ -281,7 +281,7 @@ class ModelTest(TestCase):
            "bad_kind",
        )

        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            AssertionError,
            "'order' must be either 'ASC' or 'DESC'.",
            Article.objects.dates,
@@ -323,7 +323,7 @@ class ModelTest(TestCase):
             "<Article: Third article>"])

        # Slicing works with longs (Python 2 only -- Python 3 doesn't have longs).
        if not PY3:
        if not six.PY3:
            self.assertEqual(Article.objects.all()[long(0)], a)
            self.assertQuerysetEqual(Article.objects.all()[long(1):long(3)],
                ["<Article: Second article>", "<Article: Third article>"])
@@ -369,14 +369,14 @@ class ModelTest(TestCase):
             "<Article: Updated article 8>"])

        # Also, once you have sliced you can't filter, re-order or combine
        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            AssertionError,
            "Cannot filter a query once a slice has been taken.",
            Article.objects.all()[0:5].filter,
            id=a.id,
        )

        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            AssertionError,
            "Cannot reorder a query once a slice has been taken.",
            Article.objects.all()[0:5].order_by,
@@ -411,7 +411,7 @@ class ModelTest(TestCase):

        # An Article instance doesn't have access to the "objects" attribute.
        # That's only available on the class.
        self.assertRaisesRegexp(
        six.assertRaisesRegex(self,
            AttributeError,
            "Manager isn't accessible via Article instances",
            getattr,
+4 −3
Original line number Diff line number Diff line
from __future__ import absolute_import

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db.models.loading import get_app
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import six

from .models import Empty

@@ -14,12 +14,13 @@ class EmptyModelTests(TestCase):
        m = Empty()
        self.assertEqual(m.id, None)
        m.save()
        m2 = Empty.objects.create()
        Empty.objects.create()
        self.assertEqual(len(Empty.objects.all()), 2)
        self.assertTrue(m.id is not None)
        existing = Empty(m.id)
        existing.save()


class NoModelTests(TestCase):
    """
    Test for #7198 to ensure that the proper error message is raised
@@ -32,6 +33,6 @@ class NoModelTests(TestCase):
    """
    @override_settings(INSTALLED_APPS=("modeltests.empty.no_models",))
    def test_no_models(self):
        with self.assertRaisesRegexp(ImproperlyConfigured,
        with six.assertRaisesRegex(self, ImproperlyConfigured,
                    'App with label no_models is missing a models.py module.'):
            get_app('no_models')
Loading