Example #1
0
def test_exclusion_from_instance(request):
    test_path = os.path.dirname(request.fspath)
    for tfs in TEST_FILES_EXCLUDE:
        # load the file
        tree = vspec.load_tree(os.path.join(test_path, tfs),
                               [os.path.join(test_path, "resources/")])
        assert 6 == len(tree.children)
        name_list = []
        for child in tree.children:
            name_list.append(child.qualified_name())
            if "Vehicle.ExcludeSomeThing" == child.qualified_name():
                assert VSSType.BRANCH == child.type
                assert "ExcludeSomeThing description" == child.description
                assert 1 == len(child.children)
                child_2 = child.children[0]
                assert "Vehicle.ExcludeSomeThing.ExcludeSomethingLeaf" == child_2.qualified_name(
                )
                assert "ExcludeSomethingLeaf description" == child_2.description
                assert VSSType.ACTUATOR == child_2.type

            elif "Vehicle.ExcludeNode" == child.qualified_name():
                assert "Vehicle.ExcludeNode" == child.qualified_name()
                assert "ExcludeNode description" == child.description
                assert VSSType.ATTRIBUTE == child.type

        assert "Vehicle.ExcludeSomeThing" in name_list
        assert "Vehicle.ExcludeNode" in name_list
Example #2
0
def test_complex_structures(request):

    test_path = os.path.dirname(request.fspath)

    # helper function to check, if all information are present
    def check_instance_branch(branch: VSSNode, numberOfChildren: int):
        assert branch.type == VSSType.BRANCH
        assert branch.description == "High-level vehicle data."

    for tfs in TEST_FILES_COMPLEX:
        # load the file
        tree = vspec.load_tree(os.path.join(test_path, tfs),
                               [os.path.join(test_path, "resources/")])

        # check if root node has 1 child and check first instances
        assert len(tree.children) == 1
        assert tree.children[0].qualified_name() == "Vehicle.Test1"
        check_instance_branch(tree.children[0], 2)

        # go through the instances and check if expected structure maps
        for child in tree.children[0].children:
            # 2nd level: Test1.Test2 - Test1.Test3
            assert child.qualified_name() in [
                "Vehicle.Test1.Test2", "Vehicle.Test1.Test3"
            ]
            check_instance_branch(child, 3)
            for child_2 in child.children:
                # 2nd level: Test1.Test2.Test4 - Test1.Test3.Test6
                print(child_2.qualified_name())
                assert None != re.match("^Vehicle.Test1.Test(2|3).Test(4|5|6)",
                                        child_2.qualified_name())
                check_instance_branch(child_2, 4)
                for child_3 in child_2.children:
                    # 3rd level: Test1.Test2.Test4.Test7 - Test1.Test3.Test6.Test10
                    assert None != re.match(
                        "^Vehicle.Test1.Test(2|3).Test(4|5|6).Test(7|8|9|10)",
                        child_3.qualified_name())
                    check_instance_branch(child_3, 1)
                    assert 1 == len(child_3.children)
                    child_4 = child_3.children[0]
                    # 4th level: Test1.Test2.Test4.Test7.Test11 - Test1.Test3.Test6.Test10.Test11
                    assert None != re.match(
                        "^Vehicle.Test1.Test(2|3).Test(4|5|6).Test(7|8|9|10).Test11",
                        child_4.qualified_name())
                    # All instances are expected to have one child
                    assert 1 == len(child_4.children)
                    assert child_4.children[0].name == "SomeThing"
                    assert child_4.children[0].type == VSSType.SENSOR
                    assert child_4.children[0].description == "test"
Example #3
0
def test_simple_structures(request):
    test_path = os.path.dirname(request.fspath)
    for tfs in TEST_FILES_SIMPLE:
        # load the file
        tree = vspec.load_tree(os.path.join(test_path, tfs),
                               [os.path.join(test_path, "resources/")])

        # check if root node has 3 children
        assert len(tree.children) == 3

        list_of_instances = ["Vehicle.Test1", "Vehicle.Test2", "Vehicle.Test3"]

        for child in tree.children:
            assert child.qualified_name(
            ) in list_of_instances  # < list qualified names
            assert child.type == VSSType.BRANCH
            assert child.description == "High-level vehicle data."
            assert len(
                child.children
            ) == 1  # < check that they have exactly one child, which is named...
            assert child.children[0].name == "SomeThing"  # <... SomeThing
            assert child.children[0].type == VSSType.SENSOR
            assert child.children[0].description == "test"
Example #4
0
                                tree_node.uuid))


if __name__ == "__main__":
    #
    # Check that we have the correct arguments
    #
    opts, args = getopt.getopt(sys.argv[1:], "I:")

    # Always search current directory for include_file
    include_dirs = ["."]
    for o, a in opts:
        if o == "-I":
            include_dirs.append(a)
        else:
            usage()

    if len(args) != 2:
        usage()

    try:
        tree = vspec.load_tree(args[0], include_dirs)
        csv_out = open(args[1], "w")
        print_csv_header(csv_out)
        print_csv_content(csv_out, tree)
        csv_out.write("\n")
        csv_out.close()
    except vspec.VSpecError as e:
        print(f"Error: {e}")
        exit(255)
Example #5
0

if __name__ == "__main__":
    # The arguments we accept

    parser = argparse.ArgumentParser(description='Convert vspec to csv.')
    parser.add_argument('-I', '--include-dir', action='append',  metavar='dir', type=str, default=[],
                    help='Add include directory to search for included vspec files.')
    parser.add_argument('-s', '--strict', action='store_true', help='Use strict checking: Terminate when anything not covered or not recommended by the core VSS specs is found.' )
    parser.add_argument('vspec_file', metavar='<vspec_file>', help='The vehicle specification file to convert.')
    parser.add_argument('csv_file', metavar='<csv file>', help='The file to output the CSV data to.')

    args = parser.parse_args()

    strict = args.strict

    include_dirs = ["."]
    include_dirs.extend(args.include_dir)

    try:
        tree = vspec.load_tree(
            args.vspec_file, include_dirs, merge_private=False, break_on_noncore_attribute=strict, break_on_name_style_violation=strict)
        with open(args.csv_file, "w") as f:
            print_csv_header(f)
            print_csv_content(f, tree)
            f.write("\n")

    except vspec.VSpecError as e:
        print(f"Error: {e}")
        sys.exit(255)
Example #6
0
    print(duplication_vsso)
    print(datatypes)


if __name__ == "__main__":
    #
    # Check that we have the correct arguments
    #
    opts, args = getopt.getopt(sys.argv[1:], "I:")

    # Always search current directory for include_file
    include_dirs = ["."]
    for o, a in opts:
        if o == "-I":
            include_dirs.append(a)
        else:
            usage()

    if len(args) != 2:
        usage()

    try:
        tree = vspec.load_tree(args[0], include_dirs, False, expand_inst=False)
        ttl_out = open(args[1], "w")
        print_ttl_content(ttl_out, tree)
        ttl_out.write("\n")
        ttl_out.close()
    except vspec.VSpecError as e:
        print(f"Error: {e}")
        exit(255)
Example #7
0
def main(arguments):
    parser.add_argument(
        '-I',
        '--include-dir',
        action='append',
        metavar='dir',
        type=str,
        default=[],
        help='Add include directory to search for included vspec files.')
    parser.add_argument(
        '-s',
        '--strict',
        action='store_true',
        help=
        'Use strict checking: Terminate when anything not covered or not recommended by the core VSS specs is found.'
    )
    parser.add_argument('--abort-on-non-core-attribute',
                        action='store_true',
                        help=" Terminate when non-core attribute is found.")
    parser.add_argument(
        '--abort-on-name-style',
        action='store_true',
        help=" Terminate naming style not follows recommendations.")
    parser.add_argument(
        '--format',
        metavar='format',
        type=Exporter.from_string,
        choices=list(Exporter),
        help='Output format, choose one from ' + str(Exporter._member_names_) +
        ". If omitted we try to guess form output_file suffix.")
    parser.add_argument('--no-uuid',
                        action='store_true',
                        help='Exclude uuids from generated files.')
    parser.add_argument('vspec_file',
                        metavar='<vspec_file>',
                        help='The vehicle specification file to convert.')
    parser.add_argument('output_file',
                        metavar='<output_file>',
                        help='The file to write output to.')

    for entry in Exporter:
        entry.value.add_arguments(
            parser.add_argument_group(f"{entry.name.upper()} arguments", ""))

    args = parser.parse_args(arguments)

    # Figure out output format
    if args.format != None:  # User has given format parameter
        print("Output to " + str(args.format.name) + " format")
    else:  # Else try to figure from output file suffix
        try:
            suffix = args.output_file[args.output_file.rindex(".") + 1:]
        except:
            print(
                "Can not determine output format. Try setting --format parameter"
            )
            sys.exit(-1)
        try:
            args.format = Exporter.from_string(suffix)
        except:
            print(
                "Can not determine output format. Try setting --format parameter"
            )
            sys.exit(-1)
        print("Output to " + str(args.format.name) + " format")

    include_dirs = ["."]
    include_dirs.extend(args.include_dir)

    abort_on_non_core_attribute = False
    abort_on_namestyle = False

    if args.abort_on_non_core_attribute or args.strict:
        abort_on_non_core_attribute = True
    if args.abort_on_name_style or args.strict:
        abort_on_namestyle = True

    exporter = args.format.value

    try:
        print("Loading vspec...")
        tree = vspec.load_tree(
            args.vspec_file,
            include_dirs,
            merge_private=False,
            break_on_noncore_attribute=abort_on_non_core_attribute,
            break_on_name_style_violation=abort_on_namestyle)
        print("Calling exporter...")
        exporter.export(args, tree)
        print("All done.")
    except vspec.VSpecError as e:
        print(f"Error: {e}")
        sys.exit(255)
Example #8
0
def main(arguments):
    parser.add_argument(
        '-I',
        '--include-dir',
        action='append',
        metavar='dir',
        type=str,
        default=[],
        help='Add include directory to search for included vspec files.')
    parser.add_argument(
        '-e',
        '--extended-attributes',
        type=str,
        default="",
        help=
        'Whitelisted extended attributes as comma separated list. Note, that not all exporters will support (all) extended attributes.'
    )
    parser.add_argument(
        '-s',
        '--strict',
        action='store_true',
        help=
        'Use strict checking: Terminate when anything not covered or not recommended by VSS language or extensions is found.'
    )
    parser.add_argument('--abort-on-unknown-attribute',
                        action='store_true',
                        help=" Terminate when an unknown attribute is found.")
    parser.add_argument(
        '--abort-on-name-style',
        action='store_true',
        help=" Terminate naming style not follows recommendations.")
    parser.add_argument(
        '--format',
        metavar='format',
        type=Exporter.from_string,
        choices=list(Exporter),
        help='Output format, choose one from ' + str(Exporter._member_names_) +
        ". If omitted we try to guess form output_file suffix.")
    parser.add_argument('--no-uuid',
                        action='store_true',
                        help='Exclude uuids from generated files.')
    parser.add_argument(
        '-o',
        '--overlays',
        action='append',
        metavar='overlays',
        type=str,
        default=[],
        help=
        'Add overlays that will be layered on top of the VSS file in the order they appear.'
    )
    parser.add_argument('vspec_file',
                        metavar='<vspec_file>',
                        help='The vehicle specification file to convert.')
    parser.add_argument('output_file',
                        metavar='<output_file>',
                        help='The file to write output to.')

    for entry in Exporter:
        entry.value.add_arguments(
            parser.add_argument_group(f"{entry.name.upper()} arguments", ""))

    args = parser.parse_args(arguments)

    # Figure out output format
    if args.format != None:  # User has given format parameter
        print("Output to " + str(args.format.name) + " format")
    else:  # Else try to figure from output file suffix
        try:
            suffix = args.output_file[args.output_file.rindex(".") + 1:]
        except:
            print(
                "Can not determine output format. Try setting --format parameter"
            )
            sys.exit(-1)
        try:
            args.format = Exporter.from_string(suffix)
        except:
            print(
                "Can not determine output format. Try setting --format parameter"
            )
            sys.exit(-1)
        print("Output to " + str(args.format.name) + " format")

    include_dirs = ["."]
    include_dirs.extend(args.include_dir)

    abort_on_unknown_attribute = False
    abort_on_namestyle = False

    if args.abort_on_unknown_attribute or args.strict:
        abort_on_unknown_attribute = True
    if args.abort_on_name_style or args.strict:
        abort_on_namestyle = True

    known_extended_attributes_list = args.extended_attributes.split(",")
    if len(known_extended_attributes_list) > 0:
        vspec.model.vsstree.VSSNode.whitelisted_extended_attributes = known_extended_attributes_list
        print(
            f"Known extended attributes: {', '.join(known_extended_attributes_list)}"
        )

    exporter = args.format.value

    try:
        print(f"Loading vspec from {args.vspec_file}...")
        tree = vspec.load_tree(
            args.vspec_file,
            include_dirs,
            merge_private=False,
            break_on_unknown_attribute=abort_on_unknown_attribute,
            break_on_name_style_violation=abort_on_namestyle,
            expand_inst=False)

        for overlay in args.overlays:
            print(f"Applying VSS overlay from {overlay}...")
            othertree = vspec.load_tree(
                overlay,
                include_dirs,
                merge_private=False,
                break_on_unknown_attribute=abort_on_unknown_attribute,
                break_on_name_style_violation=abort_on_namestyle,
                expand_inst=False)
            vspec.merge_tree(tree, othertree)

        vspec.expand_tree_instances(tree)

        print("Calling exporter...")
        exporter.export(args, tree)
        print("All done.")
    except vspec.VSpecError as e:
        print(f"Error: {e}")
        sys.exit(255)
Example #9
0
    strict = False
    output_uuid = True

    # Always search current directory for include_file
    include_dirs = ["."]
    for o, a in opts:
        if o == "-I":
            include_dirs.append(a)
        elif o == "-s":
            strict = True
        elif o == "--no-uuid":
            output_uuid = False
        else:
            usage()

    if len(args) != 2:
        usage()

    yaml_out = open(args[1], "w", encoding="utf-8")

    try:
        print("Loading vspec...")
        tree = vspec.load_tree(
            args[0], include_dirs, merge_private=False, break_on_noncore_attribute=strict)
        print("Recursing tree and creating YAML...")
        export_yaml(yaml_out, tree)
        print("All done.")
    except vspec.VSpecError as e:
        print(f"Error: {e}")
        exit(255)