Skip to content

Commit

Permalink
Use from django import VERSION in version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed Feb 25, 2022
1 parent 8058686 commit cc45441
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/django_jsonfield_backport/apps.py
@@ -1,7 +1,7 @@
import django
from django import VERSION as django_version
from django.apps import AppConfig

if django.VERSION >= (3, 0):
if django_version >= (3, 0):
from django.utils.translation import gettext_lazy as _
else:
from django.utils.translation import ugettext_lazy as _
Expand All @@ -14,7 +14,7 @@ class JSONFieldConfig(AppConfig):
verbose_name = _("JSONField backport from Django 3.1")

def ready(self):
if django.VERSION >= (3, 1):
if django_version >= (3, 1):
return
features.extend_default_connection()
features.connect_signal_receivers()
Expand Down
6 changes: 3 additions & 3 deletions src/django_jsonfield_backport/models.py
@@ -1,7 +1,7 @@
import json
import warnings

import django
from django import VERSION as django_version
from django.core import checks, exceptions
from django.db import NotSupportedError, connections, router
from django.db.models import lookups
Expand Down Expand Up @@ -42,7 +42,7 @@ def check(self, **kwargs):
return errors


if django.VERSION >= (3, 1):
if django_version >= (3, 1):
from django.db.models import JSONField as BuiltinJSONField

class JSONField(BuiltinJSONField):
Expand Down Expand Up @@ -344,7 +344,7 @@ def process_rhs(self, compiler, connection):
return rhs, rhs_params


if django.VERSION >= (3, 1):
if django_version >= (3, 1):
from django.db.models.fields.json import (
KeyTextTransform as BuiltinKeyTextTransform,
KeyTransform as BuiltinKeyTransform,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_deprecation.py
@@ -1,6 +1,6 @@
from unittest import skipUnless

import django
from django import VERSION as django_version
from django.core.checks import Warning as DjangoWarning
from django.test import SimpleTestCase

Expand All @@ -9,7 +9,7 @@
from .models import JSONModel


@skipUnless(django.VERSION >= (3, 1), "Only show deprecation message for Django >= 3.1.")
@skipUnless(django_version >= (3, 1), "Only show deprecation message for Django >= 3.1.")
class DeprecationTests(SimpleTestCase):
def test_model_field_deprecation_message(self):
self.assertEqual(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_extend_features.py
@@ -1,6 +1,6 @@
from unittest import mock, skipIf

import django
from django import VERSION as django_version
from django.db import connection
from django.db.backends.base.features import BaseDatabaseFeatures
from django.test import SimpleTestCase, TestCase
Expand Down Expand Up @@ -86,7 +86,7 @@ class DatabaseConnection:
self.assertIs(hasattr(connection.features, FIELD_NAME), False)


@skipIf(django.VERSION >= (3, 1), "Not applicable.")
@skipIf(django_version >= (3, 1), "Not applicable.")
class ExtendDefaultConnectionTest(TestCase):
def setUp(self):
connection.features = connection.features_class(connection)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_invalid_models.py
@@ -1,6 +1,6 @@
from unittest import skipIf

import django
from django import VERSION as django_version
from django.core.checks import Error, Warning as DjangoWarning
from django.db import connection, models
from django.test import TestCase, skipUnlessDBFeature
Expand All @@ -10,7 +10,7 @@


@isolate_apps("tests")
@skipIf(django.VERSION >= (3, 1), "Not applicable.")
@skipIf(django_version >= (3, 1), "Not applicable.")
class CheckTests(TestCase):
@skipUnlessDBFeature("supports_json_field")
def test_ordering_pointing_to_json_field_value(self):
Expand Down Expand Up @@ -53,7 +53,7 @@ class Meta:

@isolate_apps("tests")
@skipUnlessDBFeature("supports_json_field")
@skipIf(django.VERSION >= (3, 1), "Not applicable.")
@skipIf(django_version >= (3, 1), "Not applicable.")
class DefaultTests(TestCase):
def test_invalid_default(self):
class Model(models.Model):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_model_field.py
Expand Up @@ -2,7 +2,7 @@
import uuid
from unittest import mock, skipIf

import django
from django import VERSION as django_version
from django.core import serializers
from django.core.exceptions import ValidationError
from django.core.serializers.json import DjangoJSONEncoder
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_deconstruct_custom_encoder_decoder(self):
self.assertEqual(kwargs["encoder"], DjangoJSONEncoder)
self.assertEqual(kwargs["decoder"], CustomJSONDecoder)

@skipIf(django.VERSION >= (3, 1), "Not applicable.")
@skipIf(django_version >= (3, 1), "Not applicable.")
def test_get_transforms(self):
@JSONField.register_lookup
class MyTransform(Transform):
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_custom_encoder(self):


class TestFormField(SimpleTestCase):
@skipIf(django.VERSION >= (3, 1), "Not applicable.")
@skipIf(django_version >= (3, 1), "Not applicable.")
def test_formfield(self):
model_field = JSONField()
form_field = model_field.formfield()
Expand Down

0 comments on commit cc45441

Please sign in to comment.