File: test_locale.py

package info (click to toggle)
ansible-core 2.19.0~beta6-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 32,628 kB
  • sloc: python: 180,313; cs: 4,929; sh: 4,601; xml: 34; makefile: 21
file content (41 lines) | stat: -rw-r--r-- 1,652 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- 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 annotations

from unittest.mock import MagicMock

from ansible.module_utils.common.locale import get_best_parsable_locale


class TestLocale:
    """Tests for get_best_parsable_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'