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
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
36 includes = includes_collection.collect(file_ast=file_ast, plugin_options=None, use_induced_deps=False)
37 assert includes == expected_includes
38
39 includes_with_induced_deps = includes_collection.collect(file_ast=file_ast, plugin_options=None)
40 assert includes_with_induced_deps == []
41
42
43@pytest.mark.parametrize(
44 ('file_ast', 'expected_includes'),
45 [
46 pytest.param(
47 ast.File(
48 syntax='proto3',
49 file_elements=[
50 ast.Package(name='google.protobuf'),
51 ast.Import(name='google/protobuf/any.proto'),
52 ast.Message(
53 name='Option',
54 elements=[
55 ast.Field(
56 name='name',
57 number='1',
58 type='string',
59 ),
60 ast.Field(
61 name='value',
62 number=2,
63 type='Any', # <===== Type reference without package.
64 ),
65 ],
66 ),
67 ],
68 ),
69 [
70 'userver/proto-structs/io/userver/proto_structs/any.hpp',
71 'userver/proto-structs/io/userver/proto_structs/any_conv.hpp',
72 ],
73 id='type_to_any',
74 ),
75 ],
76)
77def test_deps_within_well_knowns(file_ast, expected_includes) -> None:
78 includes = includes_collection.collect(file_ast=file_ast, plugin_options=None, use_induced_deps=False)
79 assert includes == expected_includes
80
81 includes_with_induced_deps = includes_collection.collect(file_ast=file_ast, plugin_options=None)
82 assert includes_with_induced_deps == []