Skip to content

Commit 5e2d9fe

Browse files
committed
Blacken
1 parent f6af077 commit 5e2d9fe

File tree

8 files changed

+100
-51
lines changed

8 files changed

+100
-51
lines changed

betterproto/plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_py_zero(type_num: int) -> str:
122122

123123

124124
def traverse(proto_file):
125-
def _traverse(path, items, prefix = ''):
125+
def _traverse(path, items, prefix=""):
126126
for i, item in enumerate(items):
127127
# Adjust the name since we flatten the heirarchy.
128128
item.name = next_prefix = prefix + item.name

betterproto/tests/generate.py

+31-17
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
import sys
44
from typing import Set
55

6-
from betterproto.tests.util import get_directories, inputs_path, output_path_betterproto, output_path_reference, \
7-
protoc_plugin, protoc_reference
6+
from betterproto.tests.util import (
7+
get_directories,
8+
inputs_path,
9+
output_path_betterproto,
10+
output_path_reference,
11+
protoc_plugin,
12+
protoc_reference,
13+
)
814

915
# Force pure-python implementation instead of C++, otherwise imports
1016
# break things because we can't properly reset the symbol database.
@@ -20,35 +26,43 @@ def generate(whitelist: Set[str]):
2026
for test_case_name in sorted(test_case_names):
2127
test_case_path = os.path.realpath(os.path.join(inputs_path, test_case_name))
2228

23-
if whitelist and test_case_path not in path_whitelist and test_case_name not in name_whitelist:
29+
if (
30+
whitelist
31+
and test_case_path not in path_whitelist
32+
and test_case_name not in name_whitelist
33+
):
2434
continue
2535

2636
case_output_dir_reference = os.path.join(output_path_reference, test_case_name)
27-
case_output_dir_betterproto = os.path.join(output_path_betterproto, test_case_name)
37+
case_output_dir_betterproto = os.path.join(
38+
output_path_betterproto, test_case_name
39+
)
2840

29-
print(f'Generating output for {test_case_name}')
41+
print(f"Generating output for {test_case_name}")
3042
os.makedirs(case_output_dir_reference, exist_ok=True)
3143
os.makedirs(case_output_dir_betterproto, exist_ok=True)
3244

3345
protoc_reference(test_case_path, case_output_dir_reference)
3446
protoc_plugin(test_case_path, case_output_dir_betterproto)
3547

3648

37-
HELP = "\n".join([
38-
'Usage: python generate.py',
39-
' python generate.py [DIRECTORIES or NAMES]',
40-
'Generate python classes for standard tests.',
41-
'',
42-
'DIRECTORIES One or more relative or absolute directories of test-cases to generate classes for.',
43-
' python generate.py inputs/bool inputs/double inputs/enum',
44-
'',
45-
'NAMES One or more test-case names to generate classes for.',
46-
' python generate.py bool double enums'
47-
])
49+
HELP = "\n".join(
50+
[
51+
"Usage: python generate.py",
52+
" python generate.py [DIRECTORIES or NAMES]",
53+
"Generate python classes for standard tests.",
54+
"",
55+
"DIRECTORIES One or more relative or absolute directories of test-cases to generate classes for.",
56+
" python generate.py inputs/bool inputs/double inputs/enum",
57+
"",
58+
"NAMES One or more test-case names to generate classes for.",
59+
" python generate.py bool double enums",
60+
]
61+
)
4862

4963

5064
def main():
51-
if set(sys.argv).intersection({'-h', '--help'}):
65+
if set(sys.argv).intersection({"-h", "--help"}):
5266
print(HELP)
5367
return
5468
whitelist = set(sys.argv[1:])

betterproto/tests/inputs/casing/test_casing.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44

55
def test_message_attributes():
66
message = Test()
7-
assert hasattr(message, 'snake_case_message'), 'snake_case field name is same in python'
8-
assert hasattr(message, 'camel_case'), 'CamelCase field is snake_case in python'
7+
assert hasattr(
8+
message, "snake_case_message"
9+
), "snake_case field name is same in python"
10+
assert hasattr(message, "camel_case"), "CamelCase field is snake_case in python"
911

1012

1113
def test_message_casing():
12-
assert hasattr(casing, 'SnakeCaseMessage'), 'snake_case Message name is converted to CamelCase in python'
14+
assert hasattr(
15+
casing, "SnakeCaseMessage"
16+
), "snake_case Message name is converted to CamelCase in python"
1317

1418

1519
def test_enum_casing():
16-
assert hasattr(casing, 'MyEnum'), 'snake_case Enum name is converted to CamelCase in python'
20+
assert hasattr(
21+
casing, "MyEnum"
22+
), "snake_case Enum name is converted to CamelCase in python"

betterproto/tests/inputs/googletypes_response/test_googletypes_response.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import pytest
44

5-
from betterproto.tests.output_betterproto.googletypes_response.googletypes_response import TestStub
5+
from betterproto.tests.output_betterproto.googletypes_response.googletypes_response import (
6+
TestStub
7+
)
68

79

810
class TestStubChild(TestStub):
@@ -12,7 +14,7 @@ async def _unary_unary(self, route, request, response_type, **kwargs):
1214

1315
@pytest.mark.asyncio
1416
async def test():
15-
pytest.skip('todo')
17+
pytest.skip("todo")
1618
stub = TestStubChild(None)
1719
await stub.get_int64()
1820
assert stub.response_type != Optional[int]

betterproto/tests/test_features.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class TestParentMessage(betterproto.Message):
256256
some_double: float = betterproto.double_field(2)
257257
some_message: TestChildMessage = betterproto.message_field(3)
258258

259-
test = TestParentMessage().from_dict({"someInt": 0, "someDouble": 1.2,})
259+
test = TestParentMessage().from_dict({"someInt": 0, "someDouble": 1.2})
260260

261261
assert test.to_dict(include_default_values=True) == {
262262
"someInt": 0,

betterproto/tests/test_inputs.py

+30-14
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,43 @@
1515
from google.protobuf.json_format import Parse
1616

1717

18-
excluded_test_cases = {'googletypes_response', 'service'}
18+
excluded_test_cases = {"googletypes_response", "service"}
1919
test_case_names = {*get_directories(inputs_path)} - excluded_test_cases
2020

21-
plugin_output_package = 'betterproto.tests.output_betterproto'
22-
reference_output_package = 'betterproto.tests.output_reference'
21+
plugin_output_package = "betterproto.tests.output_betterproto"
22+
reference_output_package = "betterproto.tests.output_reference"
2323

2424

2525
@pytest.mark.parametrize("test_case_name", test_case_names)
2626
def test_message_can_be_imported(test_case_name: str) -> None:
27-
importlib.import_module(f"{plugin_output_package}.{test_case_name}.{test_case_name}")
27+
importlib.import_module(
28+
f"{plugin_output_package}.{test_case_name}.{test_case_name}"
29+
)
2830

2931

3032
@pytest.mark.parametrize("test_case_name", test_case_names)
3133
def test_message_can_instantiated(test_case_name: str) -> None:
32-
plugin_module = importlib.import_module(f"{plugin_output_package}.{test_case_name}.{test_case_name}")
34+
plugin_module = importlib.import_module(
35+
f"{plugin_output_package}.{test_case_name}.{test_case_name}"
36+
)
3337
plugin_module.Test()
3438

3539

3640
@pytest.mark.parametrize("test_case_name", test_case_names)
3741
def test_message_equality(test_case_name: str) -> None:
38-
plugin_module = importlib.import_module(f"{plugin_output_package}.{test_case_name}.{test_case_name}")
42+
plugin_module = importlib.import_module(
43+
f"{plugin_output_package}.{test_case_name}.{test_case_name}"
44+
)
3945
message1 = plugin_module.Test()
4046
message2 = plugin_module.Test()
4147
assert message1 == message2
4248

4349

4450
@pytest.mark.parametrize("test_case_name", test_case_names)
4551
def test_message_json(test_case_name: str) -> None:
46-
plugin_module = importlib.import_module(f"{plugin_output_package}.{test_case_name}.{test_case_name}")
52+
plugin_module = importlib.import_module(
53+
f"{plugin_output_package}.{test_case_name}.{test_case_name}"
54+
)
4755
message: betterproto.Message = plugin_module.Test()
4856
reference_json_data = get_test_case_json_data(test_case_name)
4957

@@ -60,20 +68,28 @@ def test_binary_compatibility(test_case_name: str) -> None:
6068
sym = symbol_database.Default()
6169
sym.pool = DescriptorPool()
6270

63-
reference_module_root = os.path.join(*reference_output_package.split('.'), test_case_name)
71+
reference_module_root = os.path.join(
72+
*reference_output_package.split("."), test_case_name
73+
)
6474

6575
sys.path.append(reference_module_root)
6676

6777
# import reference message
68-
reference_module = importlib.import_module(f"{reference_output_package}.{test_case_name}.{test_case_name}_pb2")
69-
plugin_module = importlib.import_module(f"{plugin_output_package}.{test_case_name}.{test_case_name}")
78+
reference_module = importlib.import_module(
79+
f"{reference_output_package}.{test_case_name}.{test_case_name}_pb2"
80+
)
81+
plugin_module = importlib.import_module(
82+
f"{plugin_output_package}.{test_case_name}.{test_case_name}"
83+
)
7084

7185
test_data = get_test_case_json_data(test_case_name)
7286

7387
reference_instance = Parse(test_data, reference_module.Test())
7488
reference_binary_output = reference_instance.SerializeToString()
7589

76-
plugin_instance_from_json: betterproto.Message = plugin_module.Test().from_json(test_data)
90+
plugin_instance_from_json: betterproto.Message = plugin_module.Test().from_json(
91+
test_data
92+
)
7793
plugin_instance_from_binary = plugin_module.Test.FromString(reference_binary_output)
7894

7995
# # Generally this can't be relied on, but here we are aiming to match the
@@ -85,13 +101,13 @@ def test_binary_compatibility(test_case_name: str) -> None:
85101
sys.path.remove(reference_module_root)
86102

87103

88-
'''
104+
"""
89105
helper methods
90-
'''
106+
"""
91107

92108

93109
def get_test_case_json_data(test_case_name):
94-
test_data_path = os.path.join(inputs_path, test_case_name, f'{test_case_name}.json')
110+
test_data_path = os.path.join(inputs_path, test_case_name, f"{test_case_name}.json")
95111
if not os.path.exists(test_data_path):
96112
return None
97113

betterproto/tests/test_service_stub.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import pytest
55
from typing import Dict
66

7-
from betterproto.tests.output_betterproto.service.service import DoThingResponse, DoThingRequest, ExampleServiceStub
7+
from betterproto.tests.output_betterproto.service.service import (
8+
DoThingResponse,
9+
DoThingRequest,
10+
ExampleServiceStub,
11+
)
12+
813

914
class ExampleService:
1015
def __init__(self, test_hook=None):
@@ -29,7 +34,7 @@ def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
2934
grpclib.const.Cardinality.UNARY_UNARY,
3035
DoThingRequest,
3136
DoThingResponse,
32-
),
37+
)
3338
}
3439

3540

@@ -94,7 +99,9 @@ async def test_service_call_lower_level_with_overrides():
9499
) as channel:
95100
stub = ExampleServiceStub(channel, deadline=deadline, metadata=metadata)
96101
response = await stub._unary_unary(
97-
"/service.ExampleService/DoThing", DoThingRequest(ITERATIONS), DoThingResponse,
102+
"/service.ExampleService/DoThing",
103+
DoThingRequest(ITERATIONS),
104+
DoThingResponse,
98105
deadline=kwarg_deadline,
99106
metadata=kwarg_metadata,
100107
)
@@ -116,7 +123,9 @@ async def test_service_call_lower_level_with_overrides():
116123
) as channel:
117124
stub = ExampleServiceStub(channel, deadline=deadline, metadata=metadata)
118125
response = await stub._unary_unary(
119-
"/service.ExampleService/DoThing", DoThingRequest(ITERATIONS), DoThingResponse,
126+
"/service.ExampleService/DoThing",
127+
DoThingRequest(ITERATIONS),
128+
DoThingResponse,
120129
timeout=kwarg_timeout,
121130
metadata=kwarg_metadata,
122131
)

betterproto/tests/util.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
66

77
root_path = os.path.dirname(os.path.realpath(__file__))
8-
inputs_path = os.path.join(root_path, 'inputs')
9-
output_path_reference = os.path.join(root_path, 'output_reference')
10-
output_path_betterproto = os.path.join(root_path, 'output_betterproto')
8+
inputs_path = os.path.join(root_path, "inputs")
9+
output_path_reference = os.path.join(root_path, "output_reference")
10+
output_path_betterproto = os.path.join(root_path, "output_betterproto")
1111

12-
if os.name == 'nt':
13-
plugin_path = os.path.join(root_path, '..', 'plugin.bat')
12+
if os.name == "nt":
13+
plugin_path = os.path.join(root_path, "..", "plugin.bat")
1414
else:
15-
plugin_path = os.path.join(root_path, '..', 'plugin.py')
15+
plugin_path = os.path.join(root_path, "..", "plugin.py")
1616

1717

1818
def get_files(path, end: str) -> Generator[str, None, None]:
@@ -44,5 +44,7 @@ def protoc_plugin(path: str, output_dir: str):
4444

4545

4646
def protoc_reference(path: str, output_dir: str):
47-
subprocess.run(f"protoc --python_out={output_dir} --proto_path={path} {path}/*.proto", shell=True)
48-
47+
subprocess.run(
48+
f"protoc --python_out={output_dir} --proto_path={path} {path}/*.proto",
49+
shell=True,
50+
)

0 commit comments

Comments
 (0)