Ejemplo n.º 1
0
def test_remove_field_not_found():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('remove', ['not_a_field'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Ejemplo n.º 2
0
def test_change_union_to_struct():
    nodes = [model.Union("MyUnion", [model.UnionMember("field1", "u32", 1)])]
    patches = {'MyUnion': [patch.Action('struct', [])]}

    patch.patch(nodes, patches)

    assert [model.Struct('MyUnion', [model.StructMember('field1', 'u32' )])] == nodes
Ejemplo n.º 3
0
def test_make_field_static_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('static', ['field2', '3'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in e.value.message
Ejemplo n.º 4
0
def test_remove_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('remove', ['field2'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can remove field only in struct: MyStruct' in str(e.value)
Ejemplo n.º 5
0
def test_remove_field_not_found():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('remove', ['not_a_field'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Ejemplo n.º 6
0
def test_make_field_static_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('static', ['field2', '3'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in e.value.message
Ejemplo n.º 7
0
def test_insert_field_no_3_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('insert', ['1', 'additional1', 'u8', 'extra'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 3 params: MyStruct' in str(e.value)
Ejemplo n.º 8
0
def test_make_field_dynamic_array():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("dynamic", ["field3", "field1"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", bound="field1"),
            ],
        )
    ] == nodes
Ejemplo n.º 9
0
def test_make_field_greedy_array():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("greedy", ["field3"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", unlimited=True),
            ],
        )
    ] == nodes
Ejemplo n.º 10
0
def test_remove_field_no_1_param():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {"MyStruct": [patch.Action("remove", ["field1", "extra_param"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Remove field must have 1 param: MyStruct" in str(e.value)
Ejemplo n.º 11
0
def test_remove_field_not_found():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {"MyStruct": [patch.Action("remove", ["not_a_field"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Member not found: MyStruct" in str(e.value)
Ejemplo n.º 12
0
def test_remove_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {"MyStruct": [patch.Action("remove", ["field2"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can remove field only in struct: MyStruct" in str(e.value)
Ejemplo n.º 13
0
def test_insert_field_index_not_an_int():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {"MyStruct": [patch.Action("insert", ["not_a_number", "additional1", "u8"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Index is not a number: MyStruct" in str(e.value)
Ejemplo n.º 14
0
def test_insert_field_no_3_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {"MyStruct": [patch.Action("insert", ["1", "additional1", "u8", "extra"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Change field must have 3 params: MyStruct" in str(e.value)
Ejemplo n.º 15
0
def test_insert_field():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {
        'MyStruct': [
            patch.Action('insert', ['1', 'additional1', 'u8']),
            patch.Action('insert', ['-1', 'additional2', 'u16']),
            patch.Action('insert', ['128', 'additional3', 'u64'])
        ]
    }

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('additional1', 'u8'),
            model.StructMember('field2', 'u32'),
            model.StructMember('additional2', 'u16'),
            model.StructMember('field3', 'u32'),
            model.StructMember('additional3', 'u64')
        ])
    ] == nodes
Ejemplo n.º 16
0
def test_make_field_static_array():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("static", ["field3", "3"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", size="3"),
            ],
        )
    ] == nodes
Ejemplo n.º 17
0
def test_change_field_type_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('type', ['field2', 'TheRealType'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct Action(action='type', params=['field2', 'TheRealType'])" == e.value.message
Ejemplo n.º 18
0
def test_make_field_static_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {"MyStruct": [patch.Action("static", ["field2", "3"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in str(e.value)
Ejemplo n.º 19
0
def test_insert_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('insert', ['1', 'additional1', 'u8'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can insert field only in struct: MyStruct' in str(e.value)
Ejemplo n.º 20
0
def test_make_field_limited_array():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", size="20"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("limited", ["field3", "field2"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", bound="field2", size="20"),
            ],
        )
    ] == nodes
Ejemplo n.º 21
0
def test_insert_field_index_not_an_int():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('insert', ['not_a_number', 'additional1', 'u8'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Index is not a number: MyStruct' in str(e.value)
Ejemplo n.º 22
0
def test_change_field_type():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("type", ["field2", "TheRealType"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "TheRealType"),
                model.StructMember("field3", "u32"),
            ],
        )
    ] == nodes
Ejemplo n.º 23
0
def test_remove_field_no_1_param():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('remove', ['field1', 'extra_param'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Remove field must have 1 param: MyStruct' in str(e.value)
Ejemplo n.º 24
0
def test_make_field_limited_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('limited', ['field3', 'field2'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in str(e.value)
Ejemplo n.º 25
0
def test_make_field_limited_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('limited', ['field3', 'field2'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in str(e.value)
Ejemplo n.º 26
0
def test_remove_field_no_1_param():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('remove', ['field1', 'extra_param'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Remove field must have 1 param: MyStruct' in str(e.value)
Ejemplo n.º 27
0
def test_remove_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('remove', ['field2'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can remove field only in struct: MyStruct' in str(e.value)
Ejemplo n.º 28
0
def test_insert_field():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {
        "MyStruct": [
            patch.Action("insert", ["1", "additional1", "u8"]),
            patch.Action("insert", ["-1", "additional2", "u16"]),
            patch.Action("insert", ["128", "additional3", "u64"]),
        ]
    }

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("additional1", "u8"),
                model.StructMember("field2", "u32"),
                model.StructMember("additional2", "u16"),
                model.StructMember("field3", "u32"),
                model.StructMember("additional3", "u64"),
            ],
        )
    ] == nodes
Ejemplo n.º 29
0
def test_change_field_type_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('type', ['field2', 'TheRealType'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct Action(action='type', params=['field2', 'TheRealType'])" == str(e.value)
Ejemplo n.º 30
0
def test_insert_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {"MyStruct": [patch.Action("insert", ["1", "additional1", "u8"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can insert field only in struct: MyStruct" in str(e.value)
Ejemplo n.º 31
0
def test_rename_field_excessive_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]

    patches = {'MyStruct': [patch.Action('rename', 3 * ['too_much_params'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Rename must have 1 or 2 params: MyStruct' in str(e.value)
Ejemplo n.º 32
0
def test_rename_field_not_composite():
    nodes = [model.Enum("MyEnum", [model.EnumMember("val", "123")])]

    patches = {'MyEnum': [patch.Action('rename', ['field3', 'field69'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can rename fields only in composites: MyEnum' in str(e.value)
Ejemplo n.º 33
0
def test_change_union_to_struct_not_a_union():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32", 1),
                                      model.StructMember("field2", "u32", 2)])]
    patches = {'MyStruct': [patch.Action('struct', [])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can only change union to struct: MyStruct' in str(e.value)
Ejemplo n.º 34
0
def test_change_union_to_struct_excessive_params():
    nodes = [model.Union("MyUnion", [model.UnionMember("field1", "u32", 1),
                                    model.UnionMember("field2", "u32", 2)])]
    patches = {'MyUnion': [patch.Action('struct', ['surplus_param'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change union to struct takes no params: MyUnion' in str(e.value)
Ejemplo n.º 35
0
def test_change_union_to_struct():
    nodes = [model.Union("MyUnion", [model.UnionMember("field1", "u32", 1)])]
    patches = {'MyUnion': [patch.Action('struct', [])]}

    patch.patch(nodes, patches)

    assert [model.Struct('MyUnion',
                         [model.StructMember('field1', 'u32')])] == nodes
Ejemplo n.º 36
0
def test_rename_field_not_composite():
    nodes = [model.Enum("MyEnum", [model.EnumMember("val", "123")])]

    patches = {'MyEnum': [patch.Action('rename', ['field3', 'field69'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can rename fields only in composites: MyEnum' in str(e.value)
Ejemplo n.º 37
0
def test_rename_field_excessive_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]

    patches = {'MyStruct': [patch.Action('rename', 3 * ['too_much_params'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Rename must have 1 or 2 params: MyStruct' in str(e.value)
Ejemplo n.º 38
0
def test_insert_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {
        'MyStruct': [patch.Action('insert', ['1', 'additional1', 'u8'])]
    }

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can insert field only in struct: MyStruct' in str(e.value)
Ejemplo n.º 39
0
def test_insert_field_index_not_an_int():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {
        'MyStruct':
        [patch.Action('insert', ['not_a_number', 'additional1', 'u8'])]
    }

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Index is not a number: MyStruct' in str(e.value)
Ejemplo n.º 40
0
def test_insert_field_no_3_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {
        'MyStruct':
        [patch.Action('insert', ['1', 'additional1', 'u8', 'extra'])]
    }

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 3 params: MyStruct' in str(e.value)
Ejemplo n.º 41
0
def main():
    opts = options.parse_options()

    if opts.version:
        print "prophyc {}".format(__version__)
        sys.exit(0)

    if not opts.input_files:
        sys.exit("prophyc: error: missing input file")

    if opts.isar:
        from prophyc.parsers.isar import IsarParser
        parser = IsarParser()
        parse_error = None
    elif opts.sack:
        if not module_exists("clang"):
            sys.exit("Sack input requires clang and it's not installed")
        from prophyc.parsers.sack import SackParser
        parser = SackParser(opts.include_dirs)
        parse_error = None
    else:
        from prophyc.parsers.prophy import ProphyParser, ParseError
        parser = ProphyParser()
        parse_error = ParseError

    serializers = []
    if opts.python_out:
        from prophyc.generators.python import PythonGenerator
        serializers.append(PythonGenerator(opts.python_out))
    if opts.cpp_out:
        from prophyc.generators.cpp import CppGenerator
        serializers.append(CppGenerator(opts.cpp_out))

    if not serializers:
        sys.exit("Missing output directives")

    for input_file in opts.input_files:
        try:
            nodes = parser.parse(input_file)
        except parse_error as e:
            sys.exit('\n'.join(e.errors))

        if opts.patch:
            from prophyc import patch
            patches = patch.parse(opts.patch)
            patch.patch(nodes, patches)
        model.topological_sort(nodes)
        model.cross_reference(nodes)
        model.evaluate_kinds(nodes)

        for serializer in serializers:
            basename = get_basename(input_file)
            serializer.serialize(nodes, basename)
Ejemplo n.º 42
0
def test_change_union_to_struct_excessive_params():
    nodes = [
        model.Union("MyUnion", [
            model.UnionMember("field1", "u32", 1),
            model.UnionMember("field2", "u32", 2)
        ])
    ]
    patches = {'MyUnion': [patch.Action('struct', ['surplus_param'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change union to struct takes no params: MyUnion' in str(e.value)
Ejemplo n.º 43
0
def test_change_union_to_struct_not_a_union():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('struct', [])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can only change union to struct: MyStruct' in str(e.value)
Ejemplo n.º 44
0
def test_change_field_type_member_not_found():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('type', ['field4', 'TheRealType'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Ejemplo n.º 45
0
def test_make_field_limited_array_with_wrong_bound_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('limited', ['field3', 'field4'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Array len member not found: MyStruct' in str(e.value)
Ejemplo n.º 46
0
def test_make_field_static_array_with_wrong_size_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('static', ['field3', 'wrong_size'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Size is not a number: MyStruct' in e.value.message
Ejemplo n.º 47
0
def test_fail_to_make_field_limited_array():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("after", "u32")
        ])
    ]

    patches = {'MyStruct': [patch.Action('limited', ['field2', 'after'])]}

    with pytest.raises(Exception, match="Array len member not found: "):
        patch.patch(nodes, patches)
Ejemplo n.º 48
0
def test_unknown_action():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('typo_or_something', [])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Unknown action: MyStruct Action(action='typo_or_something', params=[])" == e.value.message
Ejemplo n.º 49
0
def test_make_field_static_array_with_wrong_name_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('static', ['field4', '3'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Ejemplo n.º 50
0
def test_make_field_greedy_array_no_1_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]

    patches = {'MyStruct': [patch.Action('greedy', ['field2', 'extra_args'])]}
    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 1 params: MyStruct' in str(e.value)
Ejemplo n.º 51
0
def test_make_field_dynamic_array_member_not_found():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('dynamic', ['field4', 'field1'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Ejemplo n.º 52
0
def test_rename_node():
    nodes = [
        model.Struct("OldStruct", [model.StructMember("field", "u32")]),
        model.Enum("OldEnum", [model.EnumMember("val", "123")])
    ]

    patches = {
        'OldStruct': [patch.Action('rename', ['NewStruct'])],
        'OldEnum': [patch.Action('rename', ['NewEnum'])]
    }

    patch.patch(nodes, patches)

    assert nodes[0].name == 'NewStruct'
    assert nodes[1].name == 'NewEnum'
Ejemplo n.º 53
0
def test_remove_field():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('remove', ['field2'])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('field3', 'u32')
        ])
    ] == nodes
Ejemplo n.º 54
0
def test_make_field_static_array_no_2_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]

    patches = {'MyStruct': [patch.Action('static', ['field2'])]}
    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 2 params: MyStruct' in e.value.message

    patches = {'MyStruct': [patch.Action('static', ['field2', '3', 'extra'])]}
    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 2 params: MyStruct' in e.value.message
Ejemplo n.º 55
0
def test_make_field_limited_array():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32", size='20')
        ])
    ]
    patches = {'MyStruct': [patch.Action('limited', ['field3', 'field2'])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('field2', 'u32'),
            model.StructMember('field3', 'u32', bound='field2', size='20')
        ])
    ] == nodes
Ejemplo n.º 56
0
def test_change_field_type():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('type', ['field2', 'TheRealType'])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('field2', 'TheRealType'),
            model.StructMember('field3', 'u32')
        ])
    ] == nodes
Ejemplo n.º 57
0
def test_make_field_static_array():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('static', ['field3', '3'])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('field2', 'u32'),
            model.StructMember('field3', 'u32', size='3')
        ])
    ] == nodes