Skip to content

Commit 7598373

Browse files
committed
Additional test. Small bug fixes and debug code cleanup
1 parent bbb9dd6 commit 7598373

5 files changed

Lines changed: 82 additions & 10 deletions

File tree

PyAres/Analyzing/analysis_service.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,19 @@ def GetConnectionStatus(self, request, context):
137137
print(f"Exception while trying to respond to ARES with connection status! {e}")
138138

139139
def ValidateInputs(self, request: analyzer_service.ParameterValidationRequest, context):
140-
print("Validating Inputs")
141140
response = analyzer_service.ParameterValidationResult(success=True)
142141
provided_params: Mapping[str, ares_data_schema_pb2.SchemaEntry] = request.input_schema.fields
143142

144143
for stored_key, stored_schema in self._analysis_parameters.items():
145-
print(f"LOOKING AT {stored_key}")
146144
if stored_key in provided_params:
147145
matching_schema = provided_params[stored_key]
148146
if stored_schema.type != matching_schema.type:
149-
print(f" THIS IS THE TYPE RIGHT HERE LOOK AT IT: {type(matching_schema)}")
150147
message = f"Schema Mismatch! {stored_key} was provided with the value type {stored_schema.type}, but the value type {matching_schema} was expected!"
151148
response.messages.append(message)
152-
print(message)
153149
else:
154150
if not stored_schema.optional:
155151
message = f"Schema Missing! {stored_key} is marked as a required piece of data for analysis, but no assignment was found in the provided schema!"
156152
response.messages.append(message)
157-
print(message)
158153

159154
if len(response.messages) != 0:
160155
response.success = False

PyAres/Utils/ares_data_schema_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ def create_settings_schema_entry(
1515
choices: Union[list[str], list[int], list[float]],
1616
struct_schema: Optional[Dict[str, AresSchemaEntry]] = None) -> ares_data_schema_pb2.SchemaEntry:
1717
"""
18-
Takes in an AresSetting object and converts it into the protobuf SchemaEntry message.
18+
Creates a protobuf SchemaEntry message from the provided setting details.
1919
2020
Args:
21-
new_setting: The AresSetting object that provides all the details around the setting implementation.
21+
setting_type (AresDataType): The data type of the setting.
22+
optional (bool): Whether the setting is optional.
23+
choices (Union[list[str], list[int], list[float]]): A list of valid choices for the setting.
24+
struct_schema (Optional[Dict[str, AresSchemaEntry]]): Nested schema definition for STRUCT types.
2225
2326
Returns:
2427
(SchemaEntry): A new SchemaEntry message.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import unittest
2+
from PyAres.Utils import ares_data_schema_utils
3+
from PyAres.Models import AresDataType, AresSchemaEntry
4+
from ares_datamodel import ares_data_type_pb2
5+
6+
class TestAresDataSchemaUtils(unittest.TestCase):
7+
def test_create_simple_entry(self):
8+
entry = ares_data_schema_utils.create_settings_schema_entry(
9+
AresDataType.STRING,
10+
optional=True,
11+
choices=[]
12+
)
13+
self.assertEqual(entry.type, ares_data_type_pb2.AresDataType.STRING)
14+
self.assertTrue(entry.optional)
15+
16+
def test_create_entry_with_string_choices(self):
17+
choices = ["A", "B"]
18+
entry = ares_data_schema_utils.create_settings_schema_entry(
19+
AresDataType.STRING,
20+
optional=False,
21+
choices=choices
22+
)
23+
self.assertEqual(entry.string_choices.strings, choices)
24+
25+
def test_create_entry_with_number_choices(self):
26+
choices = [1, 2.0]
27+
entry = ares_data_schema_utils.create_settings_schema_entry(
28+
AresDataType.NUMBER,
29+
optional=False,
30+
choices=choices
31+
)
32+
self.assertEqual(entry.number_choices.numbers, choices)
33+
34+
def test_create_entry_with_mixed_choices(self):
35+
# Should result in no choices being set if types are mixed
36+
choices = ["A", 1]
37+
entry = ares_data_schema_utils.create_settings_schema_entry(
38+
AresDataType.STRING,
39+
optional=False,
40+
choices=choices
41+
)
42+
43+
self.assertEqual(len(entry.string_choices.strings), 0)
44+
self.assertEqual(len(entry.number_choices.numbers), 0)
45+
46+
def test_convert_ares_schema_entry_to_proto(self):
47+
py_entry = AresSchemaEntry(
48+
type=AresDataType.NUMBER,
49+
optional=True,
50+
description="Test Desc",
51+
unit="m/s",
52+
choices=[1.0, 2.0]
53+
)
54+
proto = ares_data_schema_utils.convert_ares_schema_entry_to_proto(py_entry)
55+
self.assertEqual(proto.type, ares_data_type_pb2.AresDataType.NUMBER)
56+
self.assertTrue(proto.optional)
57+
self.assertEqual(proto.description, "Test Desc")
58+
self.assertEqual(proto.unit, "m/s")
59+
self.assertEqual(proto.number_choices.numbers, [1.0, 2.0])
60+
61+
def test_nested_struct_schema(self):
62+
nested_field = AresSchemaEntry(type=AresDataType.STRING, description="Inner")
63+
struct_entry = AresSchemaEntry(
64+
type=AresDataType.STRUCT,
65+
struct_schema={"inner_key": nested_field}
66+
)
67+
68+
proto = ares_data_schema_utils.convert_ares_schema_entry_to_proto(struct_entry)
69+
self.assertEqual(proto.type, ares_data_type_pb2.AresDataType.STRUCT)
70+
self.assertIn("inner_key", proto.struct_schema.fields)
71+
72+
inner_proto = proto.struct_schema.fields["inner_key"]
73+
self.assertEqual(inner_proto.type, ares_data_type_pb2.AresDataType.STRING)
74+
self.assertEqual(inner_proto.description, "Inner")
75+
76+
if __name__ == '__main__':
77+
unittest.main(verbosity=2)

tests/test_ares_struct_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ def test_create_ares_struct_inference(self):
5252
self.assertEqual(s_list_num.fields["k"].number_array_value.numbers, [1, 2])
5353

5454
s_list_bool = ares_struct_utils.create_ares_struct("k", [True, False])
55-
blah = s_list_bool.fields["k"]
56-
bleh = blah.list_value.values
5755
self.assertEqual(s_list_bool.fields["k"].list_value.values[0].bool_value, True)
5856

5957
s_empty = ares_struct_utils.create_ares_struct("k", [])

tests/test_ares_value_type_conversions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def test_string_array_ares_value(self):
4141
original_list = ["one", "two", "three"]
4242
list_value = ares_value_utils.create_ares_value(original_list)
4343
self.assertEqual(list_value.string_array_value.strings, original_list)
44-
print("String Array Test Passed!")
4544

4645
def test_bool_array_ares_value(self):
4746
original_list = [True, False, True]

0 commit comments

Comments
 (0)