From 1eb6767beb155ba7b73472e4d76e520822423ca2 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Thu, 18 Aug 2022 10:43:24 +0200 Subject: [PATCH] Upgrade test_normalization for django 4.1 and above --- .../tests/locale/test_locale_normalization.py | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/survey/tests/locale/test_locale_normalization.py b/survey/tests/locale/test_locale_normalization.py index 00f196d2..8db3ab64 100644 --- a/survey/tests/locale/test_locale_normalization.py +++ b/survey/tests/locale/test_locale_normalization.py @@ -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)