Skip to content

Commit

Permalink
Harmonize error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ansaminard committed Dec 9, 2024
1 parent f5313c9 commit 585f38c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,47 +188,43 @@ def source_harmonics_two_parameters(self) -> FieldsContainer:
return self.__source_harmonics_two_parameters

@source_harmonics_two_parameters.setter
def source_harmonics_two_parameters(self, source_harmonics_two_parameters: FieldsContainer):
def source_harmonics_two_parameters(self, source: FieldsContainer):
"""Set the harmonics source with two parameters data, from a DPF fields container."""
if source_harmonics_two_parameters is not None:
if not isinstance(source_harmonics_two_parameters, FieldsContainer):
if source is not None:
if not isinstance(source, FieldsContainer):
raise PyAnsysSoundException(
"Specified harmonics source with two parameters must be provided as a DPF "
"fields container."
)

if len(source_harmonics_two_parameters) < 1:
if len(source) < 1:
raise PyAnsysSoundException(
"Specified harmonics source with two parameters must contain at least one "
"order."
)

for spectrum in source_harmonics_two_parameters:
for spectrum in source:
if len(spectrum.data) < 1:
raise PyAnsysSoundException(
"Each order in the specified harmonics source with two parameters must "
"contain at least one element."
)

support_data = source_harmonics_two_parameters.get_support("control_parameter_1")
support_data = source.get_support("control_parameter_1")
support_properties = support_data.available_field_supported_properties()
support_values = support_data.field_support_by_property(support_properties[0])
if len(support_values) < 1:
raise PyAnsysSoundException(
"RPM control data in the specified harmonics source with two parameters must "
"contain at least one element."
)

support_data = source_harmonics_two_parameters.get_support("control_parameter_2")
support1_values = support_data.field_support_by_property(support_properties[0])
support_data = source.get_support("control_parameter_2")
support_properties = support_data.available_field_supported_properties()
support_values = support_data.field_support_by_property(support_properties[0])
if len(support_values) < 1:
support2_values = support_data.field_support_by_property(support_properties[0])
if len(support1_values) != len(source) or len(support2_values) != len(source):
raise PyAnsysSoundException(
"Second control data in the specified harmonics source with two parameters "
"must contain at least one element."
"Harmonics source with two parameters must contain as many order levels as "
"the number of values in both associated control parameters (in the provided "
"DPF fields container, the number of fields should be the same as the number "
"of values in both fields container supports)."
)

self.__source_harmonics_two_parameters = source_harmonics_two_parameters
self.__source_harmonics_two_parameters = source

def is_source_control_valid(self) -> bool:
"""Source control verification function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,28 +233,10 @@ def test_source_harmonics_two_parameters_properties_exceptions(dpf_sound_test_se
with pytest.raises(
PyAnsysSoundException,
match=(
"RPM control data in the specified harmonics source with two parameters must contain "
"at least one element."
),
):
source_obj.source_harmonics_two_parameters = fc_source_harmonics

# Test source_harmonics_two_parameters setter exception 5 (empty harmonics source's second
# control data). For this, we use a valid dataset, and then remove the control data.
source_obj = SourceHarmonicsTwoParameters()
source_obj.load_source_harmonics_two_parameters(
pytest.data_path_sound_composer_harmonics_source_2p_in_container
)
support_data = source_obj.source_harmonics_two_parameters.get_support("control_parameter_2")
support_properties = support_data.available_field_supported_properties()
support_values = support_data.field_support_by_property(support_properties[0])
support_values.data = []
fc_source_harmonics = source_obj.source_harmonics_two_parameters
with pytest.raises(
PyAnsysSoundException,
match=(
"Second control data in the specified harmonics source with two parameters must "
"contain at least one element."
"Harmonics source with two parameters must contain as many order levels as the number "
"of values in both associated control parameters \\(in the provided DPF fields "
"container, the number of fields should be the same as the number of values in both "
"fields container supports\\)."
),
):
source_obj.source_harmonics_two_parameters = fc_source_harmonics
Expand Down

0 comments on commit 585f38c

Please sign in to comment.