15
15
from google .protobuf .json_format import Parse
16
16
17
17
18
- excluded_test_cases = {' googletypes_response' , ' service' }
18
+ excluded_test_cases = {" googletypes_response" , " service" }
19
19
test_case_names = {* get_directories (inputs_path )} - excluded_test_cases
20
20
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"
23
23
24
24
25
25
@pytest .mark .parametrize ("test_case_name" , test_case_names )
26
26
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
+ )
28
30
29
31
30
32
@pytest .mark .parametrize ("test_case_name" , test_case_names )
31
33
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
+ )
33
37
plugin_module .Test ()
34
38
35
39
36
40
@pytest .mark .parametrize ("test_case_name" , test_case_names )
37
41
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
+ )
39
45
message1 = plugin_module .Test ()
40
46
message2 = plugin_module .Test ()
41
47
assert message1 == message2
42
48
43
49
44
50
@pytest .mark .parametrize ("test_case_name" , test_case_names )
45
51
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
+ )
47
55
message : betterproto .Message = plugin_module .Test ()
48
56
reference_json_data = get_test_case_json_data (test_case_name )
49
57
@@ -60,20 +68,28 @@ def test_binary_compatibility(test_case_name: str) -> None:
60
68
sym = symbol_database .Default ()
61
69
sym .pool = DescriptorPool ()
62
70
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
+ )
64
74
65
75
sys .path .append (reference_module_root )
66
76
67
77
# 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
+ )
70
84
71
85
test_data = get_test_case_json_data (test_case_name )
72
86
73
87
reference_instance = Parse (test_data , reference_module .Test ())
74
88
reference_binary_output = reference_instance .SerializeToString ()
75
89
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
+ )
77
93
plugin_instance_from_binary = plugin_module .Test .FromString (reference_binary_output )
78
94
79
95
# # 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:
85
101
sys .path .remove (reference_module_root )
86
102
87
103
88
- '''
104
+ """
89
105
helper methods
90
- '''
106
+ """
91
107
92
108
93
109
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" )
95
111
if not os .path .exists (test_data_path ):
96
112
return None
97
113
0 commit comments