コード例 #1
0
def handle_moban_file(moban_file, options):
    """
    act upon default moban file
    """
    moban_file_configurations = data_loader.load_data(None, moban_file)
    yaml = YAML(typ="rt")
    dumped_yaml = StringIO()
    yaml.dump(moban_file_configurations, dumped_yaml)
    LOG.info(dumped_yaml.getvalue())
    if moban_file_configurations is None:
        raise exceptions.MobanfileGrammarException(
            constants.ERROR_INVALID_MOBAN_FILE % moban_file)
    if (constants.LABEL_TARGETS not in moban_file_configurations
            and constants.LABEL_COPY not in moban_file_configurations):
        raise exceptions.MobanfileGrammarException(constants.ERROR_NO_TARGETS %
                                                   moban_file)
    check_none(moban_file_configurations, moban_file)
    version = moban_file_configurations.get(constants.MOBAN_VERSION,
                                            constants.DEFAULT_MOBAN_VERSION)
    if version == constants.DEFAULT_MOBAN_VERSION:
        mobanfile.handle_moban_file_v1(moban_file_configurations, options)
    else:
        raise exceptions.MobanfileGrammarException(
            constants.MESSAGE_FILE_VERSION_NOT_SUPPORTED % version)
    hashstore.HASH_STORE.save_hashes()
コード例 #2
0
def test_overrides_a_list_of_config_files():
    base_dir = os.path.join("tests", "fixtures", "issue_126")
    config_dir = os.path.join(base_dir, "config")
    actual = load_data(config_dir, os.path.join(base_dir, "the_config.yaml"))
    expected = [
        ("key", "value"),
        ("key_from_a", "apple"),
        ("key_from_b", "bee"),
    ]
    for item, expected_item in zip(actual.items(), expected):
        eq_(item, expected_item)
コード例 #3
0
def test_overrides_select_keys():
    base_dir = os.path.join("tests", "fixtures", "issue_126")
    config_dir = os.path.join(base_dir, "config")
    actual = load_data(
        config_dir, os.path.join(base_dir, "multi-key-config-override.yaml"))
    expected = [
        ("alpha", "from config"),
        ("cat", "from config"),
        ("beta", "from b"),
    ]
    for item, expected_item in zip(actual.items(), expected):
        eq_(item, expected_item)
コード例 #4
0
 def get_data(self, file_name):
     custom_data = copy.deepcopy(OPTIONS[constants.CLI_DICT])
     try:
         data = load_data(self.context_dirs, file_name)
         merge(custom_data, data)
         merge(custom_data, self.__cached_environ_variables)
         return custom_data
     except (IOError, exceptions.IncorrectDataInput) as exception:
         # If data file doesn't exist:
         # 1. Alert the user of their (potential) mistake
         # 2. Attempt to use environment vars as data
         LOG.warn(str(exception))
         LOG.info(MESSAGE_USING_ENV_VARS)
         merge(custom_data, self.__cached_environ_variables)
         return custom_data
コード例 #5
0
def test_overrides_nested_keys():
    base_dir = os.path.join("tests", "fixtures", "issue_126")
    config_dir = os.path.join(base_dir, "config")
    actual = load_data(config_dir, os.path.join(base_dir, "raspberry.yaml"))
    expected = {
        "raspberry": {
            "other": "OpenGL 3.0",
            "version": 4,
            "memory": "4GB",
            "core": "quad",
            "wifi": "2.5 & 5.0 GHz",
            "USB": 3.0,
            "Bluetooth": 5.0,
        },
        "tessel": {
            "version": 2,
            "USB": "micro",
            "wifi": "802.11gn"
        },
    }

    eq_(dict(actual), expected)
コード例 #6
0
def test_exception_3():
    test_file = fs.path.join("tests", "fixtures", "dragon.yaml")
    load_data(None, test_file)
コード例 #7
0
def test_exception_2():
    test_file = fs.path.join("tests", "fixtures", "dragon.yaml")
    load_data(fs.path.join("tests", "fixtures", "config"), test_file)
コード例 #8
0
def test_inheritance_yaml():
    test_file = fs.path.join("tests", "fixtures", "child.yaml")
    data = load_data(fs.path.join("tests", "fixtures", "config"), test_file)
    eq_(data, {"key": "hello world", "pass": "******"})
コード例 #9
0
def test_overrides_fs_url():
    load_engine_factory_and_engines()
    base_dir = os.path.join("tests", "fixtures")
    actual = load_data(None, os.path.join(base_dir, "override_fs_url.yaml"))
    assert "requires" in actual
コード例 #10
0
def test_exception():
    test_file = fs.path.join("tests", "fixtures", "orphan.yaml")
    data = load_data(fs.path.join("tests", "fixtures", "config"), test_file)
    eq_(len(data), 0)