1
0

test_locales.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. # Import 3rd-part libs
  7. from salt.ext.six.moves import reload_module
  8. from tests.support.mock import patch
  9. from tests.support.unit import TestCase
  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. {
  24. "charmap": "utf-8",
  25. "modifier": "valencia",
  26. "codeset": "UTF-8",
  27. "language": "ca",
  28. "territory": "ES",
  29. },
  30. )
  31. def test_join_locale(self):
  32. self.assertEqual(
  33. locales.join_locale(
  34. {
  35. "charmap": "utf-8",
  36. "modifier": "valencia",
  37. "codeset": "UTF-8",
  38. "language": "ca",
  39. "territory": "ES",
  40. }
  41. ),
  42. "ca_ES.UTF-8@valencia utf-8",
  43. )
  44. def test_normalize_locale(self):
  45. self.assertEqual(
  46. locales.normalize_locale("ca_es.UTF-8@valencia utf-8"),
  47. "ca_ES.utf8@valencia",
  48. )