Skip to content

Commit

Permalink
Also test the message are recompiled
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Oct 31, 2024
1 parent 8945146 commit 588a35f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions survey/tests/locale/test_locale_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ class TestLocaleNormalization(unittest.TestCase):
LOCALE_PATH = Path("survey", "locale").absolute()

def test_normalization(self):
"""We test if the messages were properly created with makemessages --no-obsolete --no-wrap."""
"""Messages need to be created with the proper 'makemessages' then 'compilemessages'."""
if platform.system() == "Windows":
python_3 = ["py", "-3"]
else:
python_3 = ["python3"]
base_command = ["manage.py", "makemessages", "--no-obsolete", "--no-wrap", "--ignore", "venv"]
compile_message_base_command = ["manage.py", "compilemessages"]
makemessages_command = python_3 + base_command
if django_version > "3.0":
for x in settings.LANGUAGES:
Expand All @@ -27,14 +28,16 @@ def test_normalization(self):
logging.warning("Command to launch for makemessages is : %s", " ".join(makemessages_command))

subprocess.check_call(makemessages_command)
compile_message_command = python_3 + compile_message_base_command
subprocess.check_call(compile_message_command)
git_diff_command = ["git", "diff", self.LOCALE_PATH]
git_diff = subprocess.check_output(git_diff_command).decode("utf8")
command_as_str = " ".join(makemessages_command)
msg = (
"You did not update the translation following your changes. Maybe you did not use the "
"normalized 'python3 manage.py makemessages --no-obsolete --no-wrap' ? If you're "
f"working locally, just use 'git add {self.LOCALE_PATH}', we launched "
f"'{command_as_str}' during tests.\ngit diff\n{git_diff}",
f"'{command_as_str}' during tests.\ngit diff\n{git_diff}"
)
number_of_change = git_diff.count("@@") / 2
if django_version >= "4.1":
Expand All @@ -47,3 +50,12 @@ def test_normalization(self):
number_of_language = len(os.listdir(self.LOCALE_PATH))
expected_number_of_change = number_of_language
self.assertEqual(number_of_change, expected_number_of_change, msg)
number_of_bin_differring = git_diff.count("differ\n")
command_as_str = " ".join(compile_message_command)
msg = (
"You did not compile the messages following your changes. Maybe you did not use "
"'python3 manage.py compilemessages' ? If you're "
f"working locally, just use 'git add {self.LOCALE_PATH}', we launched "
f"'{command_as_str}' during tests.\ngit diff\n{git_diff}"
)
self.assertEqual(number_of_bin_differring, 0, msg)

0 comments on commit 588a35f

Please sign in to comment.