Skip to content

Commit 5c4969f

Browse files
Merge pull request #69 from boukeversteegh/pr/bugreports
Bugreports
2 parents ee362a7 + b354aeb commit 5c4969f

22 files changed

+297
-45
lines changed

betterproto/tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ betterproto/tests/test_inputs.py ..x...x..x...x.X........xx........x.....x......
8787
- `x` — XFAIL: expected failure
8888
- `X` — XPASS: expected failure, but still passed
8989

90-
Test cases marked for expected failure are declared in [inputs/xfail.py](inputs.xfail.py)
90+
Test cases marked for expected failure are declared in [inputs/config.py](inputs/config.py)

betterproto/tests/generate.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import glob
33
import os
44
import shutil
5+
import subprocess
56
import sys
67
from typing import Set
78

@@ -33,6 +34,8 @@ def generate(whitelist: Set[str]):
3334

3435
test_case_names = set(get_directories(inputs_path))
3536

37+
failed_test_cases = []
38+
3639
for test_case_name in sorted(test_case_names):
3740
test_case_input_path = os.path.realpath(
3841
os.path.join(inputs_path, test_case_name)
@@ -45,22 +48,39 @@ def generate(whitelist: Set[str]):
4548
):
4649
continue
4750

48-
test_case_output_path_reference = os.path.join(
49-
output_path_reference, test_case_name
50-
)
51-
test_case_output_path_betterproto = os.path.join(
52-
output_path_betterproto, test_case_name
51+
print(f"Generating output for {test_case_name}")
52+
try:
53+
generate_test_case_output(test_case_name, test_case_input_path)
54+
except subprocess.CalledProcessError as e:
55+
failed_test_cases.append(test_case_name)
56+
57+
if failed_test_cases:
58+
sys.stderr.write("\nFailed to generate the following test cases:\n")
59+
for failed_test_case in failed_test_cases:
60+
sys.stderr.write(f"- {failed_test_case}\n")
61+
62+
63+
def generate_test_case_output(test_case_name, test_case_input_path=None):
64+
if not test_case_input_path:
65+
test_case_input_path = os.path.realpath(
66+
os.path.join(inputs_path, test_case_name)
5367
)
5468

55-
print(f"Generating output for {test_case_name}")
56-
os.makedirs(test_case_output_path_reference, exist_ok=True)
57-
os.makedirs(test_case_output_path_betterproto, exist_ok=True)
69+
test_case_output_path_reference = os.path.join(
70+
output_path_reference, test_case_name
71+
)
72+
test_case_output_path_betterproto = os.path.join(
73+
output_path_betterproto, test_case_name
74+
)
75+
76+
os.makedirs(test_case_output_path_reference, exist_ok=True)
77+
os.makedirs(test_case_output_path_betterproto, exist_ok=True)
5878

59-
clear_directory(test_case_output_path_reference)
60-
clear_directory(test_case_output_path_betterproto)
79+
clear_directory(test_case_output_path_reference)
80+
clear_directory(test_case_output_path_betterproto)
6181

62-
protoc_reference(test_case_input_path, test_case_output_path_reference)
63-
protoc_plugin(test_case_input_path, test_case_output_path_betterproto)
82+
protoc_reference(test_case_input_path, test_case_output_path_reference)
83+
protoc_plugin(test_case_input_path, test_case_output_path_betterproto)
6484

6585

6686
HELP = "\n".join(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"UPPERCASE": 10,
3+
"UPPERCASE_V2": 10,
4+
"UPPER_CAMEL_CASE": 10
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
syntax = "proto3";
2+
3+
message Test {
4+
int32 UPPERCASE = 1;
5+
int32 UPPERCASE_V2 = 2;
6+
int32 UPPER_CAMEL_CASE = 3;
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from betterproto.tests.output_betterproto.casing_message_field_uppercase.casing_message_field_uppercase import (
2+
Test,
3+
)
4+
5+
6+
def test_message_casing():
7+
message = Test()
8+
assert hasattr(
9+
message, "uppercase"
10+
), "UPPERCASE attribute is converted to 'uppercase' in python"
11+
assert hasattr(
12+
message, "uppercase_v2"
13+
), "UPPERCASE_V2 attribute is converted to 'uppercase_v2' in python"
14+
assert hasattr(
15+
message, "upper_camel_case"
16+
), "UPPER_CAMEL_CASE attribute is converted to upper_camel_case in python"

betterproto/tests/inputs/config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Test cases that are expected to fail, e.g. unimplemented features or bug-fixes.
2+
# Remove from list when fixed.
3+
tests = {
4+
"import_root_sibling", # 61
5+
"import_child_package_from_package", # 58
6+
"import_root_package_from_child", # 60
7+
"import_parent_package_from_child", # 59
8+
"import_circular_dependency", # failing because of other bugs now
9+
"import_packages_same_name", # 25
10+
"oneof_enum", # 63
11+
"googletypes_service_returns_empty", # 9
12+
"casing_message_field_uppercase", # 11
13+
"namespace_keywords", # 70
14+
"namespace_builtin_types" # 53
15+
}
16+
17+
services = {
18+
"googletypes_response",
19+
"googletypes_response_embedded",
20+
"service",
21+
"import_service_input_message",
22+
"googletypes_service_returns_empty",
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
syntax = "proto3";
2+
3+
import "google/protobuf/empty.proto";
4+
5+
service Test {
6+
rpc Send (RequestMessage) returns (google.protobuf.Empty) {
7+
}
8+
}
9+
10+
message RequestMessage {
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
syntax = "proto3";
2+
3+
import "users_v1.proto";
4+
import "posts_v1.proto";
5+
6+
// Tests generated message can correctly reference two packages with the same leaf-name
7+
8+
message Test {
9+
users.v1.User user = 1;
10+
posts.v1.Post post = 2;
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
syntax = "proto3";
2+
3+
package posts.v1;
4+
5+
message Post {
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
syntax = "proto3";
2+
3+
package users.v1;
4+
5+
message User {
6+
7+
}

0 commit comments

Comments
 (0)