[FIX] module_auto_update: Ignore `__pycache__` in hash test
Python >= 3.2 implements [PEP 3147](https://www.python.org/dev/peps/pep-3147/), so in a precompiled environment, the patched test could fail with this or similar:
FAIL: test_basic (odoo.addons.module_auto_update.tests.test_addon_hash.TestAddonHash)
Traceback (most recent call last):
` File "/opt/odoo/auto/addons/module_auto_update/tests/test_addon_hash.py", line 42, in test_basic
` 'static/src/some.js',
` AssertionError: Lists differ: ['REA[237 chars]o', 'models/__pycache__/stuff.cpython-35.opt-1[23 chars].js'] != ['REA[237 chars]o', 'static/src/some.js']
`
` First differing element 14:
` 'models/__pycache__/stuff.cpython-35.opt-1.pyc'
` 'static/src/some.js'
`
` First list contains 1 additional elements.
` First extra element 15:
` 'static/src/some.js'
`
` ['README.rst',
` 'data/f1.xml',
` 'data/f2.xml',
` 'i18n/en.po',
` 'i18n/en_US.po',
` 'i18n/fr.po',
` 'i18n/fr_BE.po',
` 'i18n/test.pot',
` 'i18n_extra/en.po',
` 'i18n_extra/fr.po',
` 'i18n_extra/nl_NL.po',
` 'models/stuff.py',
` 'models/stuff.pyc',
` 'models/stuff.pyo',
` - 'models/__pycache__/stuff.cpython-35.opt-1.pyc',
` 'static/src/some.js']
With this patch, we fix all those failing tests in integration environments.
7 years ago [FIX] module_auto_update: Add .pyo sample file (#1205)
Without this patch, if your tests are run under a `PYTHONOPTIMIZE=2` precompiled environment, they'd fail with this error because a new `.pyo` file would be created.:
FAIL: test_basic (openerp.addons.module_auto_update.tests.test_addon_hash.TestAddonHash)
Traceback (most recent call last):
` File "/opt/odoo/auto/addons/module_auto_update/tests/test_addon_hash.py", line 41, in test_basic
` 'static/src/some.js',
` AssertionError: Lists differ: ['README.rst', 'data/f1.xml', ... != ['README.rst', 'data/f1.xml', ...
`
` First differing element 13:
` models/stuff.pyo
` static/src/some.js
`
` First list contains 1 additional elements.
` First extra element 14:
` static/src/some.js
`
` ['README.rst',
` 'data/f1.xml',
` 'data/f2.xml',
` 'i18n/en.po',
` 'i18n/en_US.po',
` 'i18n/fr.po',
` 'i18n/fr_BE.po',
` 'i18n/test.pot',
` 'i18n_extra/en.po',
` 'i18n_extra/fr.po',
` 'i18n_extra/nl_NL.po',
` 'models/stuff.py',
` 'models/stuff.pyc',
` - 'models/stuff.pyo',
` 'static/src/some.js']
Ran 3 tests in 0.005s
FAILED
With this patch, the `.pyo` file is included, so tests will pass anywhere.
7 years ago |
|
# Copyright 2018 ACSONE SA/NV. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
import os import unittest
from .. import addon_hash from ..models.module import DEFAULT_EXCLUDE_PATTERNS
class TestAddonHash(unittest.TestCase):
def setUp(self): super(TestAddonHash, self).setUp() self.sample_dir = os.path.join( os.path.dirname(__file__), 'sample_module', )
def test_basic(self): files = list(addon_hash._walk( self.sample_dir, exclude_patterns=["*/__pycache__/*"], keep_langs=[], )) self.assertEqual(files, [ 'README.rst', 'data/f1.xml', 'data/f2.xml', 'i18n/en.po', 'i18n/en_US.po', 'i18n/fr.po', 'i18n/fr_BE.po', 'i18n/test.pot', 'i18n_extra/en.po', 'i18n_extra/fr.po', 'i18n_extra/nl_NL.po', 'models/stuff.py', 'models/stuff.pyc', 'models/stuff.pyo', 'static/src/some.js', ])
def test_exclude(self): files = list(addon_hash._walk( self.sample_dir, exclude_patterns=DEFAULT_EXCLUDE_PATTERNS.split(','), keep_langs=['fr_FR', 'nl'], )) self.assertEqual(files, [ 'README.rst', 'data/f1.xml', 'data/f2.xml', 'i18n/fr.po', 'i18n/fr_BE.po', 'i18n_extra/fr.po', 'i18n_extra/nl_NL.po', 'models/stuff.py', ])
def test2(self): checksum = addon_hash.addon_hash( self.sample_dir, exclude_patterns=['*.pyc', '*.pyo', '*.pot', 'static/*'], keep_langs=['fr_FR', 'nl'], ) self.assertEqual(checksum, 'fecb89486c8a29d1f760cbd01c1950f6e8421b14')
|