示例#1
0
def test_lookup_non_existing_key(our_cwd_setup):
    tester_file_name = 'lookup_non_existing_key.yml'
    tester_file_path = os.path.join(test_utils.TESTS_CWD, tester_file_name)

    with open(tester_file_path) as fp:
        settings = yaml.load(fp)

    with pytest.raises(exceptions.IRKeyNotFoundException):
        yamls.replace_lookup(settings)
示例#2
0
def test_nested_lookup(our_cwd_setup):
    tester_file_name = 'lookup_nested.yml'
    tester_file_path = os.path.join(test_utils.TESTS_CWD, tester_file_name)

    with open(tester_file_path) as fp:
        settings = yaml.load(fp)
        yamls.replace_lookup(settings)

    assert settings['foo']['test1'] == "key was found"
示例#3
0
def test_circular_reference_lookup():
    tester_file_name = 'lookup_new_style_circular_reference.yml'
    tester_file_path = os.path.join(test_utils.TESTS_CWD, tester_file_name)

    with open(tester_file_path) as fp:
        settings = yaml.load(fp)

    with pytest.raises(exceptions.IRInfiniteLookupException):
        yamls.replace_lookup(settings)
示例#4
0
def test_in_list_lookup(our_cwd_setup):
    tester_file_name = 'lookup_in_list.yml'
    tester_file_path = os.path.join(test_utils.TESTS_CWD, tester_file_name)

    with open(tester_file_path) as fp:
        yaml_content = yaml.load(fp)
        yamls.replace_lookup(yaml_content)

    assert yaml_content['key1']['key12'] == ["pre", "found", "post"]
示例#5
0
def test_same_key_multiple_visits_lookup(our_cwd_setup):
    """
    Checks that key's path is removed from the 'visited' list when each
    lookup is found
    """
    tester_file_name = 'lookup_same_key_multiple_visits.yml'
    tester_file_path = os.path.join(test_utils.TESTS_CWD, tester_file_name)

    with open(tester_file_path) as fp:
        yaml_content = yaml.load(fp)
        yamls.replace_lookup(yaml_content)

    assert yaml_content['key']['sub2'] == 'val-val'
示例#6
0
def test_integer_key_conversion_in_lookup(our_cwd_setup):
    """
    Makes sure that integer keys remain integer after lookup method
    """
    tester_file_name = 'lookup_int_key_conversion.yml'
    tester_file_path = os.path.join(test_utils.TESTS_CWD, tester_file_name)

    with open(tester_file_path) as fp:
        yaml_content = yaml.load(fp)
        yamls.replace_lookup(yaml_content)

    assert yaml_content['key'][1] == 'val'
    with pytest.raises(KeyError):
        yaml_content['key']['1'] == 'val'
示例#7
0
    def _lookup(self, settings_files, settings_dict, extra_vars=None):
        """
        Replaces a setting values with !lookup
        in the setting files by values from
        other settings files.
        """
        all_settings = utils.load_settings_files(settings_files)
        utils.dict_merge(all_settings, settings_dict)
        utils.merge_extra_vars(
            all_settings,
            extra_vars)
        yamls.replace_lookup(all_settings)

        return all_settings