Skip to content

Commit

Permalink
[FIX] test_new_api: mitigate babel issue
Browse files Browse the repository at this point in the history
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]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

X-original-commit: 426fc56
  • Loading branch information
d-fence committed Jun 10, 2024
1 parent 43339f5 commit a1805f3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion odoo/addons/test_new_api/tests/test_properties.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a1805f3

Please sign in to comment.