userver: /data/code/userver/libraries/proto-structs/codegen-tests/pytest/ast/test_includes_list.py Source File
Loading...
Searching...
No Matches
test_includes_list.py
1from proto_schema_parser import ast # noqa: I001
2from proto_schema_parser import parser
3from proto_structs.ast import includes_collection
4import pytest
5
6import utils
7
8
9@pytest.mark.parametrize(
10 ('proto_path', 'expected_includes'),
11 [
12 pytest.param(
13 'enums/names.proto',
14 [],
15 id='enums',
16 ),
17 pytest.param(
18 'maps/basic.proto',
19 [
20 'userver/proto-structs/io/userver/proto_structs/hash_map.hpp',
21 'userver/proto-structs/io/userver/proto_structs/hash_map_conv.hpp',
22 ],
23 id='maps',
24 ),
25 pytest.param(
26 'box/autobox/unbreakable_cycle.proto',
27 [],
28 id='unbreakable_cycle',
29 ),
30 ],
31)
32def test_includes_are_correct(proto_path, expected_includes) -> None:
33 proto_source = utils.load_proto_source_file(proto_path)
34 file_ast = parser.Parser().parse(proto_source)
35 includes = includes_collection.collect(file_ast=file_ast, plugin_options=None)
36 assert includes == expected_includes
37
38
39@pytest.mark.parametrize(
40 ('file_ast', 'expected_includes'),
41 [
42 pytest.param(
43 ast.File(
44 syntax='proto3',
45 file_elements=[
46 ast.Package(name='google.protobuf'),
47 ast.Import(name='google/protobuf/any.proto'),
48 ast.Message(
49 name='Option',
50 elements=[
51 ast.Field(
52 name='name',
53 number='1',
54 type='string',
55 ),
56 ast.Field(
57 name='value',
58 number=2,
59 type='Any', # <===== Type reference without package.
60 ),
61 ],
62 ),
63 ],
64 ),
65 [
66 'userver/proto-structs/io/userver/proto_structs/any.hpp',
67 'userver/proto-structs/io/userver/proto_structs/any_conv.hpp',
68 ],
69 id='type_to_any',
70 ),
71 ],
72)
73def test_deps_within_well_knowns(file_ast, expected_includes) -> None:
74 includes = includes_collection.collect(file_ast=file_ast, plugin_options=None)
75 assert includes == expected_includes