8000 Define __all__ (#625) · danielgtaylor/python-betterproto@1a23f09 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a23f09

Browse files
Define __all__ (#625)
* Define __all__ * Use tuple instead of list * Add test
1 parent 335eee7 commit 1a23f09

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/betterproto/templates/header.py.j2

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
# sources: {{ ', '.join(output_file.input_filenames) }}
33
# plugin: python-betterproto
44
# This file has been @generated
5+
6+
__all__ = (
7+
{%- for enum in output_file.enums -%}
8+
"{{ enum.py_name }}",
9+
{%- endfor -%}
10+
{%- for message in output_file.messages -%}
11+
"{{ message.py_name }}",
12+
{%- endfor -%}
13+
{%- for service in output_file.services -%}
14+
"{{ service.py_name }}Stub",
15+
"{{ service.py_name }}Base",
16+
{%- endfor -%}
17+
)
18+
519
{% for i in output_file.python_module_imports|sort %}
620
import {{ i }}
721
{% endfor %}

tests/test_all_definition.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def test_all_definition():
2+
"""
3+
Check that a compiled module defines __all__ with the right value.
4+
5+
These modules have been chosen since they contain messages, services and enums.
6+
"""
7+
import tests.output_betterproto.enum as enum
8+
import tests.output_betterproto.service as service
9+
10+
assert service.__all__ == (
11+
"ThingType",
12+
"DoThingRequest",
13+
"DoThingResponse",
14+
"GetThingRequest",
15+
"GetThingResponse",
16+
"TestStub",
17+
"TestBase",
18+
)
19+
assert enum.__all__ == ("Choice", "ArithmeticOperator", "Test")

0 commit comments

Comments
 (0)
0