test_locales.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # coding: utf-8
  2. # Import Python libs
  3. from __future__ import absolute_import, unicode_literals
  4. # Import Salt libs
  5. import salt.utils.locales as locales
  6. from tests.support.unit import TestCase, skipIf
  7. from tests.support.mock import patch, NO_MOCK, NO_MOCK_REASON
  8. # Import 3rd-part libs
  9. from salt.ext.six.moves import reload_module
  10. @skipIf(NO_MOCK, NO_MOCK_REASON)
  11. class TestLocales(TestCase):
  12. def test_get_encodings(self):
  13. # reload locales modules before and after to defeat memoization of
  14. # get_encodings()
  15. reload_module(locales)
  16. with patch('sys.getdefaultencoding', return_value='xyzzy'):
  17. encodings = locales.get_encodings()
  18. for enc in (__salt_system_encoding__, 'xyzzy', 'utf-8', 'latin-1'):
  19. self.assertIn(enc, encodings)
  20. reload_module(locales)
  21. def test_split_locale(self):
  22. self.assertDictEqual(
  23. locales.split_locale('ca_ES.UTF-8@valencia utf-8'),
  24. {'charmap': 'utf-8',
  25. 'modifier': 'valencia',
  26. 'codeset': 'UTF-8',
  27. 'language': 'ca',
  28. 'territory': 'ES'})
  29. def test_join_locale(self):
  30. self.assertEqual(
  31. locales.join_locale(
  32. {'charmap': 'utf-8',
  33. 'modifier': 'valencia',
  34. 'codeset': 'UTF-8',
  35. 'language': 'ca',
  36. 'territory': 'ES'}),
  37. 'ca_ES.UTF-8@valencia utf-8')
  38. def test_normalize_locale(self):
  39. self.assertEqual(
  40. locales.normalize_locale('ca_es.UTF-8@valencia utf-8'),
  41. 'ca_ES.utf8@valencia')