From c3c465551cc0b500d3bd3b46287191db6ec26d76 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 7 Dec 2020 11:27:02 +0000 Subject: [PATCH] [FIX] test_lint: check for duplicate entries in POT files X-original-commit: 4e29fbada592e887459dabee71708c6d0dd01715 --- addons/l10n_ch/i18n/l10n_ch.pot | 1 + odoo/addons/test_lint/tests/__init__.py | 1 + odoo/addons/test_lint/tests/test_pofile.py | 29 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 odoo/addons/test_lint/tests/test_pofile.py diff --git a/addons/l10n_ch/i18n/l10n_ch.pot b/addons/l10n_ch/i18n/l10n_ch.pot index a020dcca858..030abb9a50b 100644 --- a/addons/l10n_ch/i18n/l10n_ch.pot +++ b/addons/l10n_ch/i18n/l10n_ch.pot @@ -559,6 +559,7 @@ msgstr "" msgid "type: [(name, amount, base, formated amount, formated base)]" msgstr "" +#. module: l10n_ch #: code:addons/l10n_ch/models/account_invoice.py:179 #, python-format msgid "Cannot generate the QR-bill. Please check you have configured the address of your company and debtor. If you are using a QR-IBAN, also check the invoice's payment reference is a QR reference." diff --git a/odoo/addons/test_lint/tests/__init__.py b/odoo/addons/test_lint/tests/__init__.py index 681e1270bb5..c28bef7f107 100644 --- a/odoo/addons/test_lint/tests/__init__.py +++ b/odoo/addons/test_lint/tests/__init__.py @@ -1,4 +1,5 @@ from . import test_pylint +from . import test_pofile from . import test_ecmascript from . import test_markers from . import test_onchange_domains diff --git a/odoo/addons/test_lint/tests/test_pofile.py b/odoo/addons/test_lint/tests/test_pofile.py new file mode 100644 index 00000000000..61f34a4cc94 --- /dev/null +++ b/odoo/addons/test_lint/tests/test_pofile.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from collections import Counter + +from odoo.modules import get_modules, get_resource_path +from odoo.tests.common import TransactionCase +from odoo.tools.translate import TranslationFileReader + + +class PotLinter(TransactionCase): + def test_pot_duplicate_entries(self): + def format(entry): + # TranslationFileReader only returns those three types + if entry['type'] == 'model': + return ('model', entry['name'], entry['imd_name']) + elif entry['type'] == 'model_terms': + return ('model_terms', entry['name'], entry['imd_name'], entry['src']) + elif entry['type'] == 'code': + return ('code', entry['src']) + + # retrieve all modules, and their corresponding POT file + for module in get_modules(): + filename = get_resource_path(module, 'i18n', module + '.pot') + if not filename: + continue + counts = Counter(map(format, TranslationFileReader(filename))) + duplicates = [key for key, count in counts.items() if count > 1] + self.assertFalse(duplicates, "Duplicate entries found in %s" % filename)