Skip to content

Commit

Permalink
Merge pull request #17 from browniebroke/festure/ungettext_lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed May 10, 2020
2 parents c340222 + 13f9f1a commit b345818
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Currently implemented:
* ``django_codemod.commands.django_40.UNGetTextToNGetTextCommand``: migrate deprecated
``ungettext()`` function to ``ngettext()``.

* ``django_codemod.commands.django_40.UNGetTextLazyToNGetTextLazyCommand``: migrate deprecated
``ungettext_lazy()`` function to ``ngettext_lazy()``.

Credits
-------

Expand Down
8 changes: 8 additions & 0 deletions django_codemod/commands/django_40.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,11 @@ class UNGetTextToNGetTextCommand(UGetTextToGetTextCommand):
DESCRIPTION: str = "Replaces ungettext() by ngettext()."
old_name = "ungettext"
new_name = "ngettext"


class UNGetTextLazyToNGetTextLazyCommand(UGetTextToGetTextCommand):
"""Help resolve deprecation of django.utils.translation.ungettext_lazy."""

DESCRIPTION: str = "Replaces ungettext_lazy() by ngettext_lazy()."
old_name = "ungettext_lazy"
new_name = "ngettext_lazy"
51 changes: 51 additions & 0 deletions tests/commands/test_django_40.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
UGetTextLazyToGetTextLazyCommand,
UGetTextNoopToGetTextNoopCommand,
UNGetTextToNGetTextCommand,
UNGetTextLazyToNGetTextLazyCommand,
)


Expand Down Expand Up @@ -328,3 +329,53 @@ def test_already_imported_substitution(self) -> None:
result = ngettext(content, plural_content, count)
"""
self.assertCodemod(before, after)


class TestUNGetTextLazyToNGetTextLazyCommand(CodemodTest):

TRANSFORM = UNGetTextLazyToNGetTextLazyCommand

def test_noop(self) -> None:
"""Test when nothing should change."""
before = """
from django import conf
from django.utils import translation
foo = ngettext_lazy("bar", "bars", count)
"""
after = """
from django import conf
from django.utils import translation
foo = ngettext_lazy("bar", "bars", count)
"""

self.assertCodemod(before, after)

def test_simple_substitution(self) -> None:
"""Check simple use case."""
before = """
from django.utils.translation import ungettext_lazy
result = ungettext_lazy(content, plural_content, count)
"""
after = """
from django.utils.translation import ngettext_lazy
result = ngettext_lazy(content, plural_content, count)
"""
self.assertCodemod(before, after)

def test_already_imported_substitution(self) -> None:
"""Test case where ngettext_lazy is already in the imports."""
before = """
from django.utils.translation import ungettext_lazy, ngettext_lazy
result = ungettext_lazy(content, plural_content, count)
"""
after = """
from django.utils.translation import ngettext_lazy
result = ngettext_lazy(content, plural_content, count)
"""
self.assertCodemod(before, after)

0 comments on commit b345818

Please sign in to comment.