diff options
Diffstat (limited to 'test/units/config/test_manager.py')
-rw-r--r-- | test/units/config/test_manager.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/test/units/config/test_manager.py b/test/units/config/test_manager.py index 8ef40437..0848276c 100644 --- a/test/units/config/test_manager.py +++ b/test/units/config/test_manager.py @@ -10,7 +10,7 @@ import os import os.path import pytest -from ansible.config.manager import ConfigManager, Setting, ensure_type, resolve_path, get_config_type +from ansible.config.manager import ConfigManager, ensure_type, resolve_path, get_config_type from ansible.errors import AnsibleOptionsError, AnsibleError from ansible.module_utils.six import integer_types, string_types from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode @@ -18,6 +18,7 @@ from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode curdir = os.path.dirname(__file__) cfg_file = os.path.join(curdir, 'test.cfg') cfg_file2 = os.path.join(curdir, 'test2.cfg') +cfg_file3 = os.path.join(curdir, 'test3.cfg') ensure_test_data = [ ('a,b', 'list', list), @@ -65,6 +66,15 @@ ensure_test_data = [ ('None', 'none', type(None)) ] +ensure_unquoting_test_data = [ + ('"value"', '"value"', 'str', 'env'), + ('"value"', '"value"', 'str', 'yaml'), + ('"value"', 'value', 'str', 'ini'), + ('\'value\'', 'value', 'str', 'ini'), + ('\'\'value\'\'', '\'value\'', 'str', 'ini'), + ('""value""', '"value"', 'str', 'ini') +] + class TestConfigManager: @classmethod @@ -79,6 +89,11 @@ class TestConfigManager: def test_ensure_type(self, value, expected_type, python_type): assert isinstance(ensure_type(value, expected_type), python_type) + @pytest.mark.parametrize("value, expected_value, value_type, origin", ensure_unquoting_test_data) + def test_ensure_type_unquoting(self, value, expected_value, value_type, origin): + actual_value = ensure_type(value, value_type, origin) + assert actual_value == expected_value + def test_resolve_path(self): assert os.path.join(curdir, 'test.yml') == resolve_path('./test.yml', cfg_file) @@ -142,3 +157,16 @@ class TestConfigManager: actual_value = ensure_type(vault_var, value_type) assert actual_value == "vault text" + + +@pytest.mark.parametrize(("key", "expected_value"), ( + ("COLOR_UNREACHABLE", "bright red"), + ("COLOR_VERBOSE", "rgb013"), + ("COLOR_DEBUG", "gray10"))) +def test_256color_support(key, expected_value): + # GIVEN: a config file containing 256-color values with default definitions + manager = ConfigManager(cfg_file3) + # WHEN: get config values + actual_value = manager.get_config_value(key) + # THEN: no error + assert actual_value == expected_value |