Skip to content

Commit

Permalink
Upgrade test_normalization for django 4.1 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Aug 18, 2022
1 parent 51e6ed2 commit 1eb6767
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions survey/tests/locale/test_locale_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,32 @@ def test_normalization(self):
python_3 = ["py", "-3"]
else:
python_3 = ["python3"]
makemessages_command = python_3 + [
"manage.py",
"makemessages",
"--no-obsolete",
"--no-wrap",
"--ignore",
"venv",
]
base_command = ["manage.py", "makemessages", "--no-obsolete", "--no-wrap", "--ignore", "venv"]
makemessages_command = python_3 + base_command
if django_version > "3.0":
for x in settings.LANGUAGES:
if x[0] not in ["en"]:
makemessages_command += ["--locale", x[0]]
logging.warning("Command to launch for makemessages is : %s", " ".join(makemessages_command))
number_of_language = len(os.listdir(self.LOCALE_PATH))

subprocess.check_call(makemessages_command)
git_diff_command = ["git", "diff", self.LOCALE_PATH]
git_diff = subprocess.check_output(git_diff_command).decode("utf8")
# In the diff we should have a change only for the date of the generation
# So 2 * @@ * number of language
command_as_str = " ".join(makemessages_command)
number_of_change = git_diff.count("@@") / 2
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}",
)
self.assertEqual(number_of_change, number_of_language, msg)
number_of_change = git_diff.count("@@") / 2
if django_version >= "4.1":
# There's no date modification when there isn't any change for
# django above 4.1.0
expected_number_of_change = 0
else:
# In the diff we should have a change only for the date of the generation
# So 2 * @@ * number of language
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)

0 comments on commit 1eb6767

Please sign in to comment.