test_locales.py 1.6 KB

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