示例#1
0
def test_assert_key_has_value_fails_key_error_message():
    """KeyNotInContextError if context missing key, assert message correct."""
    context = Context({'key1': 'value1'})
    with pytest.raises(KeyNotInContextError) as err_info:
        context.assert_key_has_value('notindict', 'mydesc')

    assert repr(
        err_info.value) == ("KeyNotInContextError(\"context['notindict'] "
                            "doesn't exist. It must exist for "
                            "mydesc.\",)")
示例#2
0
文件: filespec.py 项目: fvutils/mkdv
def run_step(context: Context):
    print("filespec: %s" % str(context))

    context.assert_key_has_value("vlnv", "filespec")
    context.assert_key_exists("out", "filespec")

    vlnv = context.get_formatted("vlnv")

    dbm = CoreDbMgr.inst()

    deps = dbm.get_depends(vlnv)

    for e in context["out"]:
        if "name" not in e.keys():
            raise KeyNotInContextError("Missing 'name'")
        if "type" not in e.keys():
            raise KeyNotInContextError("Missing 'type'")
        name = e["name"]

        file_types = set()
        for t in e["type"]:
            file_types.add(t.strip())

        flags = {}
        if "flags" in e.keys():
            for f in e["flags"]:
                flags[f] = True

        is_include = False
        if "include" in e.keys():
            is_include = bool(e["include"])

        files = dbm.collect_files(deps, file_types, flags, is_include)

        if name in context.keys():
            if isinstance(context[name], list):
                context[name].extend(files)
            elif isinstance(context[name], str):
                context[name] += " ".join(files)
            else:
                raise Exception("Target for files is an unsupported type %s" %
                                str(type(context[name])))
        else:
            context[name] = files
示例#3
0
def test_assert_key_has_bool_false_passes():
    """Pass if key_in_dict_has_value dictionary key has bool False value."""
    context = Context({'key1': False})
    context.assert_key_has_value('key1', None)
示例#4
0
def test_assert_key_has_value_passes():
    """Pass if key_in_dict_has_value dictionary key has value."""
    context = Context({'key1': 'value1'})
    context.assert_key_has_value('key1', None)
示例#5
0
def test_assert_key_has_value_fails_key_empty():
    """KeyInContextHasNoValueError if context dictionary key value is None."""
    context = Context({'key1': None})
    with pytest.raises(KeyInContextHasNoValueError):
        context.assert_key_has_value('key1', None)
示例#6
0
def test_assert_key_has_value_fails_key_not_found():
    """KeyNotInContextError if context doesn't have key on assert."""
    context = Context({'key1': 'value1'})
    with pytest.raises(KeyNotInContextError):
        context.assert_key_has_value('notindict', None)
示例#7
0
def test_assert_key_has_value_fails_on_key_none():
    """Expect AssertionError if assert key is None."""
    context = Context({'key1': 'value1'})
    with pytest.raises(AssertionError):
        context.assert_key_has_value(None, None)
示例#8
0
def test_assert_key_has_value_fails_on_context_empty():
    """Expect KeyNotInContextError if context empty."""
    context = Context()
    with pytest.raises(KeyNotInContextError):
        context.assert_key_has_value('key', 'desc')