You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

  1. # Copyright 2018 ACSONE SA/NV.
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  3. import os
  4. import unittest
  5. from .. import addon_hash
  6. from ..models.module import DEFAULT_EXCLUDE_PATTERNS
  7. class TestAddonHash(unittest.TestCase):
  8. def setUp(self):
  9. super(TestAddonHash, self).setUp()
  10. self.sample_dir = os.path.join(
  11. os.path.dirname(__file__),
  12. 'sample_module',
  13. )
  14. def test_basic(self):
  15. files = list(addon_hash._walk(
  16. self.sample_dir,
  17. exclude_patterns=["*/__pycache__/*"],
  18. keep_langs=[],
  19. ))
  20. self.assertEqual(files, [
  21. 'README.rst',
  22. 'data/f1.xml',
  23. 'data/f2.xml',
  24. 'i18n/en.po',
  25. 'i18n/en_US.po',
  26. 'i18n/fr.po',
  27. 'i18n/fr_BE.po',
  28. 'i18n/test.pot',
  29. 'i18n_extra/en.po',
  30. 'i18n_extra/fr.po',
  31. 'i18n_extra/nl_NL.po',
  32. 'models/stuff.py',
  33. 'models/stuff.pyc',
  34. 'models/stuff.pyo',
  35. 'static/src/some.js',
  36. ])
  37. def test_exclude(self):
  38. files = list(addon_hash._walk(
  39. self.sample_dir,
  40. exclude_patterns=DEFAULT_EXCLUDE_PATTERNS.split(','),
  41. keep_langs=['fr_FR', 'nl'],
  42. ))
  43. self.assertEqual(files, [
  44. 'README.rst',
  45. 'data/f1.xml',
  46. 'data/f2.xml',
  47. 'i18n/fr.po',
  48. 'i18n/fr_BE.po',
  49. 'i18n_extra/fr.po',
  50. 'i18n_extra/nl_NL.po',
  51. 'models/stuff.py',
  52. ])
  53. def test2(self):
  54. checksum = addon_hash.addon_hash(
  55. self.sample_dir,
  56. exclude_patterns=['*.pyc', '*.pyo', '*.pot', 'static/*'],
  57. keep_langs=['fr_FR', 'nl'],
  58. )
  59. self.assertEqual(checksum, 'fecb89486c8a29d1f760cbd01c1950f6e8421b14')