From a1805f3000d874cb11ecee68da993937999ca46c Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Wed, 5 Jun 2024 10:54:34 +0200 Subject: [PATCH] [FIX] test_new_api: mitigate babel issue Since Babel issue 621 [0] searching the week number of a date alongside with the year can lead to a wrong year in the result. e.g.: `2023-01-01` gives `W1 2022` Before the present commit, the tests were surprisingly expecting the wrong result. An attempt was made [1] to fix the upstream issue but was never merged. In the meanwhile, Debian reverted the Babel issue 621 [2] in their package. It means that our test would fail with the patched Debian package like in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the test to expect the correct value, it would fail on unpatched version of the Babel lib. So, this commit mitigate the issue by guessing the expected value even if the result is wrong. [0]: https://github.com/python-babel/babel/pull/621 [1]: https://github.com/python-babel/babel/pull/887 [2]: https://sources.debian.org/patches/python-babel/2.10.3-1/ X-original-commit: 426fc568d33ec952ed4784eb0c6c9d74f343aa5f --- odoo/addons/test_new_api/tests/test_properties.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/odoo/addons/test_new_api/tests/test_properties.py b/odoo/addons/test_new_api/tests/test_properties.py index 96cb2d5492495..772f88571ce3f 100644 --- a/odoo/addons/test_new_api/tests/test_properties.py +++ b/odoo/addons/test_new_api/tests/test_properties.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import babel.dates import datetime import json import unittest @@ -2399,7 +2400,16 @@ def test_properties_field_read_group_date_week(self, date_type='date'): self.assertEqual(result[3]['attributes.mydate_count'], 1) self.assertEqual(result[3]['attributes.mydate:week'], 'W5 2023') self.assertEqual(result[4]['attributes.mydate_count'], 2) - self.assertEqual(result[4]['attributes.mydate:week'], 'W1 2022') + # Babel issue mitigation + # https://github.com/python-babel/babel/pull/621 -- introduced a new bug + # https://github.com/python-babel/babel/pull/887 -- proposed a fix but finally closed + # https://sources.debian.org/patches/python-babel/2.10.3-1/ -- Debian reverted 621 + # so this ugly fix is made to have the test working in patched and non patched versions of Babel + babel_year = babel.dates.format_date(datetime.datetime(2023, 1, 1), "YYYY", "en_US") # non patched: '2022' patched: '2023' + if babel_year == '2022': # Broken unpatched babel + self.assertEqual(result[4]['attributes.mydate:week'], 'W1 2022') + else: # Patched babel + self.assertEqual(result[4]['attributes.mydate:week'], 'W1 2023') # check domain self.assertEqual(Model.search(result[0]['__domain']), self.message_6 | self.message_7) self.assertEqual(Model.search(result[1]['__domain']), self.message_5)