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.

68 lines
1.8 KiB

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