Skip to content

Commit

Permalink
Oneof test fixes (#286)
Browse files Browse the repository at this point in the history
* fix test runner, enum name, fix nested test

* adding debug print statements, enabling oneof tests

---------

Co-authored-by: pratheekshasn <[email protected]>
  • Loading branch information
CPattar-NI and pratheekshasn authored Aug 8, 2023
1 parent 42935f1 commit 26c6d81
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 28 deletions.
Binary file modified tests/New_ATS/Tests/enum-oneof/Impl/Start Sync.vi
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/New_ATS/Tests/enum-oneof/enum-oneof_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_GetFeature_output(test_input):
response_dict = {}
response_dict['res_latitude'] = response.res_latitude
response_dict['res_oneof'] = {}
response_dict['res_oneof']['res_color'] = enum_oneof_pb2.Color(response.res_color) if response.HasField('res_color') else None
response_dict['res_oneof']['res_color'] = enum_oneof_pb2.Color.Name(response.res_color) if response.HasField('res_color') else None
response_dict['res_oneof']['res_name'] = response.res_name if response.HasField('res_name') else None

return(response_dict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ message res {
oneof res_oneof {
string res_name = 2;
int32 res_num = 3;
bool flag = 4;
float price = 5;
bool flag = 4;
}
}

Expand All @@ -21,7 +21,7 @@ message req {
oneof req_oneof {
string req_name = 2;
int32 req_num = 3;
bool flag = 4;
float price = 5;
bool flag = 4;
}
}
Binary file modified tests/New_ATS/Tests/nested-oneof/Impl/Start Sync.vi
Binary file not shown.
1 change: 1 addition & 0 deletions tests/New_ATS/Tests/nested-oneof/nested-oneof.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ message res {
}

message MessageA {
string anotherField = 3;
oneof oneof_a {
string data_a1 = 1;
string data_a2 = 2;
Expand Down
36 changes: 23 additions & 13 deletions tests/New_ATS/Tests/nested-oneof/nested-oneof_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,42 @@

def get_GetFeature_output(test_input):
req_id = test_input.get('req_id')
req_price = test_input['req_oneof'].get('req_price')
data_a1 = data_a2 = None
req_price = data_a1 = data_a2 = anotherField = None
if test_input['req_oneof'].get('req_price'):
req_price = test_input['req_oneof'].get('req_price')
if test_input['req_oneof'].get('message_a'):
data_a1 = test_input['req_oneof'].get('message_a').get(data_a1)
data_a2 = test_input['req_oneof'].get('message_a').get(data_a2)
anotherField = test_input['req_oneof'].get('message_a').get('anotherField')
data_a1 = test_input['req_oneof'].get('message_a').get('oneof_a').get('data_a1')
data_a2 = test_input['req_oneof'].get('message_a').get('oneof_a').get('data_a2')
with grpc.insecure_channel('localhost:50051') as channel:
stub = nested_oneof_pb2_grpc.GreeterServiceStub(channel)
request = nested_oneof_pb2.req()
request.req_id = 100
# request.message_a.data_a1 = "Yash"
request.message_a.data_a2 = "Yash"
# request.req_price = req_price
request.req_id = req_id
if req_price != None:
request.req_price = req_price
if data_a1 != None:
request.message_a.data_a1 = data_a1
if data_a2 != None:
request.message_a.data_a2 = data_a2
if anotherField != None:
request.message_a.anotherField = anotherField

print(request)
response = stub.GetFeature(request)
print(response)
response_dict = {}
response_dict['res_id'] = response.res_id
response_dict['res_oneof'] = {}
response_dict['res_oneof'] = {}
if response.HasField('res_price'):
response_dict['res_oneof']['res_price'] = response.res_price
if response.HasField('message_a'):
response_dict['res_oneof']['message_a'] = {}
response_dict['res_oneof']['message_a']['oneof_a'] = {}
response_dict['res_oneof']['message_a']['anotherField'] = response.message_a.anotherField
if response.message_a.HasField('data_a1'):
response_dict['res_oneof']['message_a']['data_a1'] = response.message_a.data_a1
response_dict['res_oneof']['message_a']['oneof_a']['data_a1'] = response.message_a.data_a1
if response.message_a.HasField('data_a2'):
response_dict['res_oneof']['message_a']['data_a2'] = response.message_a.data_a2
response_dict['res_oneof']['message_a']['oneof_a']['data_a2'] = response.message_a.data_a2
return(response_dict)

def read_json(filepath):
Expand All @@ -48,6 +59,5 @@ def test_SayHello(testcase):
assert get_GetFeature_output(test_input) == expected

if __name__ == "__main__":
# response = get_GetFeature_output({"req_id":100, "req_oneof":{"req_price":20.06}})
response = get_GetFeature_output({"req_id":100, "req_oneof":{"message_a":{"data_a1":"Yash"}}})
response = get_GetFeature_output({'req_id': 561, 'req_oneof': {'message_a': {'anotherField': 'JustAnotherField', 'oneof_a': {'data_a2': 'Ankush'}}}})
print(response)
12 changes: 8 additions & 4 deletions tests/New_ATS/Tests/nested-oneof/testcases/GetFeature.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"message_a": {
"oneof_a": {
"data_a1": "Yash"
}
},
"anotherField": "bleh"
}
}
},
Expand All @@ -30,7 +31,8 @@
"message_a": {
"oneof_a": {
"data_a1": "Yash_response"
}
},
"anotherField": "bleh_response"
}
}
}
Expand All @@ -42,7 +44,8 @@
"message_a": {
"oneof_a": {
"data_a2": "Ankush"
}
},
"anotherField": "bleh"
}
}
},
Expand All @@ -52,7 +55,8 @@
"message_a": {
"oneof_a": {
"data_a2": "Ankush_response"
}
},
"anotherField": "bleh_response"
}
}
}
Expand Down
24 changes: 18 additions & 6 deletions tests/New_ATS/pylib/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,26 @@ def run_test(test_config):
check_for_pre_requisites(test_config)

# 2. Generate the server
print ("Generating server code for " + test_config['test_name'])
generate_server(test_config)

# 3. Copy the 'Run Service.vi' from the Impl folder to the Generated_server folder
run_service_impl_path = test_config['impl'] / 'Run Service.vi'
run_service_gen_path = test_config['generated_server'] / 'Run Service.vi'
shutil.copyfile(run_service_impl_path, run_service_gen_path)
if pathlib.Path(test_config['generated_server']).exists():
print (f"Copying 'Run Service.vi' to {run_service_gen_path}")
shutil.copyfile(run_service_impl_path, run_service_gen_path)
else:
print (f"{test_config['generated_server']} not generated")

# 4. Copy the 'Start Sync.vi' from the Impl folder to the "Generated_server/RPC Service/GreeterService/Server API" folder
start_sync_impl_path = test_config['impl'] / 'Start Sync.vi'
start_sync_gen_path = test_config['generated_server'] / 'RPC Service' / 'GreeterService' / 'Server API' / 'Start Sync.vi'
shutil.copyfile(start_sync_impl_path, start_sync_gen_path)
if pathlib.Path(test_config['generated_server']).exists():
print (f"Copying 'Start Sync.vi' to {start_sync_gen_path}")
shutil.copyfile(start_sync_impl_path, start_sync_gen_path)
else:
print (f"{test_config['generated_server']} not generated")

# 5. Quit LabVIEW if it is running
run_command(['taskkill', '/f', '/im', 'labview.exe'])
Expand All @@ -86,6 +95,7 @@ def run_test(test_config):
])

# TODO Check whether labviewCLI is installed or not before running the command
print ("Running the server on the LabVIEW side")
run_command(CLI_command)

# 7. Create python virtual environment
Expand All @@ -94,7 +104,7 @@ def run_test(test_config):
])
run_command(CLI_command)

# 7. Generate python grpc classes
# 8. Generate python grpc classes
generate_command = ' '.join([
f"{test_config['python_path']} -m grpc_tools.protoc",
f"--proto_path={test_config['test_folder']}",
Expand All @@ -103,23 +113,25 @@ def run_test(test_config):
f"--grpc_python_out={test_config['test_folder']}",
f"{test_config['test_name']}.proto"
])
print ("Compiling proto file")
run_command(generate_command)

# 8. Call the TestServer() from test_folder/test_name_client.py
# 9. Call the TestServer() from test_folder/test_name_client.py and get the return value
client_py_path = test_config['test_folder'] / str(test_config['test_name'] + '_client.py')
run_client_command = ' '.join([
str(test_config['test_suite_folder'] / 'RunPythonClient.bat'),
str(client_py_path),
test_config['test_name']
])
print ("Running python client")
output = run_command(run_client_command)
print(output)
FAILED += count_failed_testcases(output)

# 8. Quit LabVIEW if it is running
# 10. Quit LabVIEW if it is running
run_command(['taskkill', '/f', '/im', 'labview.exe'])

# 9. Delete python grpc generated files
# 10. Delete python grpc generated files
# for filename in os.listdir(test_config['test_folder']):
# if "pb2" in filename:
# os.remove(test_config['test_folder'] / filename)
Expand Down
4 changes: 2 additions & 2 deletions tests/New_ATS/pylib/testlist.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
{
"name": ["helloworld"],
"name": ["enum-oneof", "helloworld", "message-oneof", "multiple-field-oneof", "nested-oneof", "sibling-oneof", "simple-oneof"],
"gen_type": "0",
"labview_version": "2019",
"labview_bitness": "32"
}
]
]

0 comments on commit 26c6d81

Please sign in to comment.