Skip to content

Commit

Permalink
chore(pre-commit.ci): auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 12, 2023
1 parent 41cb654 commit ec4c4d3
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 27 deletions.
12 changes: 9 additions & 3 deletions tests/visitors/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class TestInlineHasAddPermissionsTransformer(BaseVisitorTest):
]
)
def test_noop_import_star(self, import_line: str, base_class: str) -> None:
before = after = f"""
before = (
after
) = f"""
{import_line}
class MyInlineInline(InlineMixin, {base_class}):
Expand All @@ -33,7 +35,9 @@ def has_add_permission(self, request):

def test_model_admin_base_class(self) -> None:
"""Doesn't modify if base class doesn't match."""
before = after = """
before = (
after
) = """
from django.contrib import admin
class MyAdmin(admin.ModelAdmin):
Expand All @@ -47,7 +51,9 @@ def has_add_permission(self, request):

def test_no_base_class(self) -> None:
"""Doesn't modify if there is no base class."""
before = after = """
before = (
after
) = """
from django.contrib import admin
class MyCustomStuff:
Expand Down
24 changes: 18 additions & 6 deletions tests/visitors/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ def test_kwargs(self) -> None:
self.assertCodemod(before, after)

def test_avoid_try_import(self) -> None:
before = after = """
before = (
after
) = """
try:
from django.dummy.module import func
except:
Expand All @@ -291,7 +293,9 @@ def test_avoid_try_import(self) -> None:

@pytest.mark.usefixtures("parent_module_import_enabled")
def test_avoid_try_import_parent(self) -> None:
before = after = """
before = (
after
) = """
try:
from django.dummy import module
except:
Expand All @@ -304,7 +308,9 @@ def test_avoid_try_import_parent(self) -> None:

@pytest.mark.usefixtures("parent_module_import_enabled")
def test_parent_import_star(self) -> None:
before = after = """
before = (
after
) = """
from django.dummy import *
result = module.func()
Expand All @@ -313,7 +319,9 @@ def test_parent_import_star(self) -> None:

@pytest.mark.usefixtures("parent_module_import_enabled")
def test_parent_import_not_matches(self) -> None:
before = after = """
before = (
after
) = """
from django.ymmud import other_module
result = other_module.other_func()
Expand Down Expand Up @@ -407,7 +415,9 @@ def test_parent_module_import_alias_other_usage(self) -> None:
@pytest.mark.usefixtures("parent_module_import_enabled")
def test_parent_module_noop(self) -> None:
"""Parent module imported, but other function used."""
before = after = """
before = (
after
) = """
from django.dummy import module
result = module.other_func()
Expand Down Expand Up @@ -466,7 +476,9 @@ def test_simple_substitution(self) -> None:
self.assertCodemod(before, after)

def test_avoid_try_import(self) -> None:
before = after = """
before = (
after
) = """
try:
from django.dummy.module import func
except:
Expand Down
12 changes: 9 additions & 3 deletions tests/visitors/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,19 @@ class TestHttpRequestXReadLinesTransformer(BaseVisitorTest):

def test_noop_wrong_name(self) -> None:
"""Don't replace calls for name other than `request` or `req`."""
before = after = """
before = (
after
) = """
for line in r.xreadlines():
print(line)
"""
self.assertCodemod(before, after)

def test_noop_function_call(self) -> None:
"""Don't replace calls for name other than `request` or `req`."""
before = after = """
before = (
after
) = """
for line in xreadlines(r):
print(line)
"""
Expand Down Expand Up @@ -169,7 +173,9 @@ class TestCookieDateTransformer(BaseVisitorTest):
transformer = CookieDateTransformer

def test_noop(self):
before = after = """
before = (
after
) = """
from django.utils.http import http_date
http_date(12345)
Expand Down
12 changes: 9 additions & 3 deletions tests/visitors/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ class TestAvailableAttrsTransformer(BaseVisitorTest):
)
def test_noop_import_star(self, import_str: str) -> None:
"""Should not try to replace if import star is used."""
before = after = f"""
before = (
after
) = f"""
{import_str}
class MyModel(models.Model):
Expand Down Expand Up @@ -350,7 +352,9 @@ class TestNullBooleanFieldTransformer(BaseVisitorTest):
transformer = NullBooleanFieldTransformer

def test_noop_models(self) -> None:
before = after = """
before = (
after
) = """
from django.db import models
class MyThing(models.Model):
Expand All @@ -359,7 +363,9 @@ class MyThing(models.Model):
self.assertCodemod(before, after)

def test_noop_fields(self) -> None:
before = after = """
before = (
after
) = """
from django.db.models import BooleanField, Model
class MyThing(Model):
Expand Down
4 changes: 3 additions & 1 deletion tests/visitors/test_paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class TestQuerySetPaginatorTransformer(BaseVisitorTest):

def test_noop(self) -> None:
"""Test when nothing should change."""
before = after = """
before = (
after
) = """
from django.core.paginator import Paginator
paginator_instance = Paginator([], 5)
Expand Down
12 changes: 9 additions & 3 deletions tests/visitors/test_postgres_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class TestFloatRangeModelFieldTransformer(BaseVisitorTest):

def test_noop(self) -> None:
"""Test when nothing should change."""
before = after = """
before = (
after
) = """
from django.contrib.postgres.fields import DecimalRangeField
some_range = DecimalRangeField()
Expand Down Expand Up @@ -40,7 +42,9 @@ class TestFloatRangeFormFieldTransformer(BaseVisitorTest):

def test_noop(self) -> None:
"""Test when nothing should change."""
before = after = """
before = (
after
) = """
from django.contrib.postgres.forms import DecimalRangeField
some_range = DecimalRangeField()
Expand Down Expand Up @@ -69,7 +73,9 @@ class TestJSONModelFieldTransformer(BaseVisitorTest):

def test_noop(self) -> None:
"""Test when nothing should change."""
before = after = """
before = (
after
) = """
from django.db.models import JSONField
field = JSONField()
Expand Down
8 changes: 6 additions & 2 deletions tests/visitors/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class TestSignalDisconnectWeakTransformer(BaseVisitorTest):

@parameterized.expand(DJANGO_SIGNAL_NAMES)
def test_noop(self, signal_name):
before = after = f"""
before = (
after
) = f"""
from django.db.models.signals import {signal_name}
{signal_name}.disconnect(
Expand All @@ -38,7 +40,9 @@ def test_noop(self, signal_name):

@parameterized.expand(DJANGO_SIGNAL_NAMES)
def test_noop_import_star(self, signal_name):
before = after = f"""
before = (
after
) = f"""
from django.db.models.signals import *
{signal_name}.disconnect(receiver=some_handler, sender=MyModel, weak=True)
Expand Down
16 changes: 12 additions & 4 deletions tests/visitors/test_template_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class TestAssignmentTagTransformer(BaseVisitorTest):

def test_noop(self) -> None:
"""Test when nothing should change."""
before = after = """
before = (
after
) = """
from django import template
register = template.Library()
Expand All @@ -30,7 +32,9 @@ def some_tag():
)
def test_noop_not_imported(self, import_line: str) -> None:
"""Test when import is missing."""
before = after = f"""
before = (
after
) = f"""
{import_line}
@register.assignment_tag
Expand All @@ -42,7 +46,9 @@ def some_tag():

def test_noop_import_star(self) -> None:
"""Test when imported as star import."""
before = after = """
before = (
after
) = """
from django import *
register = template.Library()
Expand Down Expand Up @@ -132,7 +138,9 @@ def some_tag():

def test_noop_content_star_import(self) -> None:
"""Test when Library class is imported as star import."""
before = after = """
before = (
after
) = """
from django.template import *
register = Library()
Expand Down
8 changes: 6 additions & 2 deletions tests/visitors/test_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class TestFixedOffsetTransformer(BaseVisitorTest):

def test_noop(self) -> None:
"""Test when nothing should change."""
before = after = """
before = (
after
) = """
from datetime import timedelta, timezone
timezone(offset=timedelta(minutes=60))
Expand Down Expand Up @@ -76,7 +78,9 @@ def test_with_name_args(self) -> None:
self.assertCodemod(before, after)

def test_issue_421(self) -> None:
before = after = """
before = (
after
) = """
from django.utils import timezone
now = timezone.now()
Expand Down

0 comments on commit ec4c4d3

Please sign in to comment.