Exemplo n.º 1
0
def test_rules_expansion_idempotent():
    # TODO: copy
    expanded = expand_rules(deepcopy(test1))
    result = expand_rules(deepcopy(expanded))
    if result != expanded:
        print("result:")
        pprint(result)
        print("expected:")
        pprint(expanded)
    assert result == expanded
Exemplo n.º 2
0
def main(args=None):
    args = command_handle_args(args, definition)
    try:
        # prepare arguments
        filepath = os.path.abspath(os.path.expanduser(args.rules_file))

        # parse rules file
        with open(filepath, 'rb') as f:
            data = to_str(f.read())
        rules = load_yaml(data)
        rules = expand_rules(rules)
        verify_rules_dict(rules)

        # compact rules
        compacted = compact_rules(rules,
                                  OSSupport().get_default_installer_names())

        # output result
        dump = dump_yaml(compacted)
        if args.write:
            with open(filepath, 'wb') as f:
                f.write(to_bytes(dump))
        else:
            info(dump)
    except (KeyboardInterrupt, EOFError):
        sys.exit(1)
Exemplo n.º 3
0
def main(args=None):
    args = command_handle_args(args, definition)
    try:
        # prepare arguments
        filepath = os.path.abspath(os.path.expanduser(args.rules_file))

        # parse rules file
        with open(filepath, 'rb') as f:
            data = to_str(f.read())
        rules = load_yaml(data)
        rules = expand_rules(rules)
        verify_rules_dict(rules)

        # compact rules
        compacted = compact_rules(
            rules, OSSupport().get_default_installer_names())

        # output result
        dump = dump_yaml(compacted)
        if args.write:
            with open(filepath, 'wb') as f:
                f.write(to_bytes(dump))
        else:
            info(dump)
    except (KeyboardInterrupt, EOFError):
        sys.exit(1)
Exemplo n.º 4
0
def test_rules_expansion():
    # TODO: copy input to expand_rules
    result = expand_rules(deepcopy(test1))
    if result != expected1:
        print("result:")
        pprint(result)
        print("expected:")
        pprint(expected1)
    assert result == expected1
Exemplo n.º 5
0
def test_merge_rules_filters_installers():
    """Test merging rules dicts: unknown os names are fileterd out."""
    rules1 = _parse_rules("""
        füü:
            other_os:
                some_version: [füü]
        """)

    rules2 = _parse_rules("""
        füü:
            any_os:
                bar: [füü]
        bar:
            osx:
                any_version:
                    bar: [bar]
            other_os:
                any_version:
                    bar: [bar]
        baß:
            other_os:
                any_version:
                    bar: [baß]
        """)

    expected = _parse_rules("""
        füü:
            any_os:
                any_version:
                    bar: [füü]
        bar:
            osx:
                any_version:
                    bar: [bar]
        """)

    _do_merge_test([rules2], expand_rules(expected))
    _do_merge_test([rules1, rules2], expand_rules(expected))
Exemplo n.º 6
0
def test_rules_compacting():
    expanded = expand_rules(deepcopy(test1))
    result = compact_rules(deepcopy(expanded), _default_installers)
    result2 = compact_rules(deepcopy(expected1), _default_installers)
    if result != expected2:
        print("result:")
        pprint(result)
        print("expected:")
        pprint(expected2)
    if result2 != expected2:
        print("result:")
        pprint(result2)
        print("expected:")
        pprint(expected2)
    assert result == expected2
    assert result2 == expected2
Exemplo n.º 7
0
def _parse_rules(rules_str):
    rules = expand_rules(load_yaml(rules_str))
    verify_rules_dict(rules)
    return rules