"Fossies" - the Fresh Open Source Software Archive

Member "salt-3002.2/tests/integration/modules/test_localemod.py" (18 Nov 2020, 2601 Bytes) of package /linux/misc/salt-3002.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_localemod.py": 3002.1_vs_3002.2.

    1 import pytest
    2 import salt.utils.platform
    3 from tests.support.case import ModuleCase
    4 from tests.support.helpers import destructiveTest, requires_salt_modules, slowTest
    5 from tests.support.unit import skipIf
    6 
    7 
    8 @skipIf(salt.utils.platform.is_windows(), "minion is windows")
    9 @skipIf(salt.utils.platform.is_darwin(), "locale method is not supported on mac")
   10 @skipIf(
   11     salt.utils.platform.is_freebsd(),
   12     "locale method is supported only within login classes or environment variables",
   13 )
   14 @requires_salt_modules("locale")
   15 @pytest.mark.windows_whitelisted
   16 class LocaleModuleTest(ModuleCase):
   17     def _find_new_locale(self, current_locale):
   18         test_locales = ["en_US.UTF-8", "de_DE.UTF-8", "fr_FR.UTF-8", "en_AU.UTF-8"]
   19         for locale in test_locales:
   20             if locale != current_locale and self.run_function("locale.avail", [locale]):
   21                 return locale
   22 
   23         self.skipTest(
   24             "The test locals: {} do not exist on the host. Skipping test.".format(
   25                 ",".join(test_locales)
   26             )
   27         )
   28 
   29     def test_get_locale(self):
   30         locale = self.run_function("locale.get_locale")
   31         self.assertNotIn("Unsupported platform!", locale)
   32 
   33     @destructiveTest
   34     @slowTest
   35     def test_gen_locale(self):
   36         # Make sure charmaps are available on test system before attempting
   37         # call gen_locale. We log this error to the user in the function, but
   38         # we don't want to fail this test if this is missing on the test system.
   39         char_maps = self.run_function("cmd.run_all", ["locale -m"])
   40         if char_maps["stdout"] == "":
   41             self.skipTest("locale charmaps not available. Skipping test.")
   42 
   43         if char_maps["retcode"] and char_maps["stderr"]:
   44             self.skipTest(
   45                 "{}. Cannot generate locale. Skipping test.".format(char_maps["stderr"])
   46             )
   47 
   48         locale = self.run_function("locale.get_locale")
   49         new_locale = self._find_new_locale(locale)
   50         ret = self.run_function("locale.gen_locale", [new_locale])
   51         self.assertTrue(ret)
   52 
   53     @destructiveTest
   54     @slowTest
   55     def test_set_locale(self):
   56         original_locale = self.run_function("locale.get_locale")
   57         locale_to_set = self._find_new_locale(original_locale)
   58         self.run_function("locale.gen_locale", [locale_to_set])
   59         ret = self.run_function("locale.set_locale", [locale_to_set])
   60         new_locale = self.run_function("locale.get_locale")
   61         self.assertTrue(ret)
   62         self.assertEqual(locale_to_set, new_locale)
   63         self.run_function("locale.set_locale", [original_locale])