diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /test/units/module_utils/common/test_locale.py | |
parent | Initial commit. (diff) | |
download | ansible-core-8a754e0858d922e955e71b253c139e071ecec432.tar.xz ansible-core-8a754e0858d922e955e71b253c139e071ecec432.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/units/module_utils/common/test_locale.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/units/module_utils/common/test_locale.py b/test/units/module_utils/common/test_locale.py new file mode 100644 index 0000000..9d95986 --- /dev/null +++ b/test/units/module_utils/common/test_locale.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# (c) Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +from units.compat.mock import MagicMock + +from ansible.module_utils.common.locale import get_best_parsable_locale + + +class TestLocale: + """Tests for get_best_paresable_locale""" + + mock_module = MagicMock() + mock_module.get_bin_path = MagicMock(return_value='/usr/bin/locale') + + def test_finding_best(self): + self.mock_module.run_command = MagicMock(return_value=(0, "C.utf8\nen_US.utf8\nC\nPOSIX\n", '')) + locale = get_best_parsable_locale(self.mock_module) + assert locale == 'C.utf8' + + def test_finding_last(self): + self.mock_module.run_command = MagicMock(return_value=(0, "fr_FR.utf8\nen_UK.utf8\nC\nPOSIX\n", '')) + locale = get_best_parsable_locale(self.mock_module) + assert locale == 'C' + + def test_finding_middle(self): + self.mock_module.run_command = MagicMock(return_value=(0, "fr_FR.utf8\nen_US.utf8\nC\nPOSIX\n", '')) + locale = get_best_parsable_locale(self.mock_module) + assert locale == 'en_US.utf8' + + def test_finding_prefered(self): + self.mock_module.run_command = MagicMock(return_value=(0, "es_ES.utf8\nMINE\nC\nPOSIX\n", '')) + locale = get_best_parsable_locale(self.mock_module, preferences=['MINE', 'C.utf8']) + assert locale == 'MINE' + + def test_finding_C_on_no_match(self): + self.mock_module.run_command = MagicMock(return_value=(0, "fr_FR.UTF8\nMINE\n", '')) + locale = get_best_parsable_locale(self.mock_module) + assert locale == 'C' |