Skip to content

Commit

Permalink
Merge pull request #15 from browniebroke/feature/ungettext_noop
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke authored May 10, 2020
2 parents b1d77b7 + 842fc59 commit be0f210
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Currently implemented:
* ``django_codemod.commands.django_40.UGetTextLazyToGetTextLazyCommand``: migrate deprecated
``ugettext_lazy()`` function to ``gettext_lazy()``.

* ``django_codemod.commands.django_40.UGetTextNoopToGetTextNoopCommand``: migrate deprecated
``ugettext_noop()`` function to ``gettext_noop()``.

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 @@ -99,3 +99,11 @@ class UGetTextLazyToGetTextLazyCommand(UGetTextToGetTextCommand):
DESCRIPTION: str = "Replaces ugettext_lazy() by gettext_lazy()."
old_name = "ugettext_lazy"
new_name = "gettext_lazy"


class UGetTextNoopToGetTextNoopCommand(UGetTextToGetTextCommand):
"""Help resolve deprecation of django.utils.translation.ugettext_noop."""

DESCRIPTION: str = "Replaces ugettext_noop() by gettext_noop()."
old_name = "ugettext_noop"
new_name = "gettext_noop"
59 changes: 55 additions & 4 deletions tests/commands/test_django_40.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
SmartTextToForceStrCommand,
UGetTextToGetTextCommand,
UGetTextLazyToGetTextLazyCommand,
UGetTextNoopToGetTextNoopCommand,
)


Expand Down Expand Up @@ -43,7 +44,7 @@ def test_simple_substitution(self) -> None:
"""
self.assertCodemod(before, after)

def test_str_already_imported_substitution(self) -> None:
def test_already_imported_substitution(self) -> None:
"""Test case where force_str is already in the imports."""
before = """
from django.utils.encoding import force_text, force_str
Expand Down Expand Up @@ -113,7 +114,7 @@ def test_simple_substitution(self) -> None:
"""
self.assertCodemod(before, after)

def test_str_already_imported_substitution(self) -> None:
def test_already_imported_substitution(self) -> None:
"""Test case where smart_str is already in the imports."""
before = """
from django.utils.encoding import smart_text, smart_str
Expand Down Expand Up @@ -163,7 +164,7 @@ def test_simple_substitution(self) -> None:
"""
self.assertCodemod(before, after)

def test_str_already_imported_substitution(self) -> None:
def test_already_imported_substitution(self) -> None:
"""Test case where gettext is already in the imports."""
before = """
from django.utils.translation import ugettext, gettext
Expand Down Expand Up @@ -213,7 +214,7 @@ def test_simple_substitution(self) -> None:
"""
self.assertCodemod(before, after)

def test_str_already_imported_substitution(self) -> None:
def test_already_imported_substitution(self) -> None:
"""Test case where gettext_lazy is already in the imports."""
before = """
from django.utils.translation import ugettext_lazy, gettext_lazy
Expand All @@ -226,3 +227,53 @@ def test_str_already_imported_substitution(self) -> None:
result = gettext_lazy(content)
"""
self.assertCodemod(before, after)


class TestUGetTextNoopToGetTextNoopCommand(CodemodTest):

TRANSFORM = UGetTextNoopToGetTextNoopCommand

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

self.assertCodemod(before, after)

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

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

0 comments on commit be0f210

Please sign in to comment.