Skip to content

Commit

Permalink
reformatted on ruff 0.9 (RascalSoftware#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhroom authored Jan 9, 2025
1 parent 4af2abf commit 082657c
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions RATapi/classlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __str__(self):
[
[index]
+ list(
f"{'Data array: ['+' x '.join(str(i) for i in v.shape) if v.size > 0 else '['}]"
f"{'Data array: [' + ' x '.join(str(i) for i in v.shape) if v.size > 0 else '['}]"
if isinstance(v, np.ndarray)
else "\n".join(element for element in v)
if k == "model"
Expand Down Expand Up @@ -364,7 +364,7 @@ def _check_unique_name_fields(self, input_list: Sequence[T]) -> None:
if new_indices:
new_list = ", ".join(str(i) for i in new_indices[:-1])
new_string = (
f" item{f's {new_list} and ' if new_list else ' '}" f"{new_indices[-1]} of the input list"
f" item{f's {new_list} and ' if new_list else ' '}{new_indices[-1]} of the input list"
)
error_list.append(
f" '{name}' is shared between{existing_string}"
Expand Down
6 changes: 3 additions & 3 deletions RATapi/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def warn_setting_incorrect_properties(self, handler: ValidatorFunctionWrapHandle
procedure = input_dict.get("procedure", Procedures.Calculate)
custom_error_msgs = {
"extra_forbidden": f'Extra inputs are not permitted. The fields for the "{procedure}"'
f' controls procedure are:\n '
f'{", ".join(fields.get("procedure", []))}\n',
f" controls procedure are:\n "
f"{', '.join(fields.get('procedure', []))}\n",
}
custom_error_list = custom_pydantic_validation_error(exc.errors(), custom_error_msgs)
raise ValidationError.from_exception_data(exc.title, custom_error_list, hide_input=True) from None
Expand All @@ -116,7 +116,7 @@ def warn_setting_incorrect_properties(self, handler: ValidatorFunctionWrapHandle
f'\nThe current controls procedure is "{new_procedure}", but the property'
f' "{field}" applies instead to the {", ".join(incorrect_procedures)} procedure.\n\n'
f' The fields for the "{new_procedure}" controls procedure are:\n'
f' {", ".join(fields[new_procedure])}\n',
f" {', '.join(fields[new_procedure])}\n",
stacklevel=2,
)

Expand Down
6 changes: 3 additions & 3 deletions RATapi/examples/languages/run_custom_file_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
start = time.time()
project, results = RAT.run(project, controls)
end = time.time()
print(f"Python time is: {end-start}s\n")
print(f"Python time is: {end - start}s\n")

RAT.plotting.plot_ref_sld(project, results)

Expand All @@ -27,7 +27,7 @@
start = time.time()
project, results = RAT.run(project, controls)
end = time.time()
print(f"Matlab time is: {end-start}s\n")
print(f"Matlab time is: {end - start}s\n")

RAT.plotting.plot_ref_sld(project, results)

Expand All @@ -37,6 +37,6 @@
start = time.time()
project, results = RAT.run(project, controls)
end = time.time()
print(f"C++ time is: {end-start}s\n")
print(f"C++ time is: {end - start}s\n")

RAT.plotting.plot_ref_sld(project, results)
2 changes: 1 addition & 1 deletion RATapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def __eq__(self, other: object) -> bool:
def __str__(self):
table = prettytable.PrettyTable()
table.field_names = [key.replace("_", " ") for key in self.__dict__]
array_entry = f"{'Data array: ['+' x '.join(str(i) for i in self.data.shape) if self.data.size > 0 else '['}]"
array_entry = f"{'Data array: [' + ' x '.join(str(i) for i in self.data.shape) if self.data.size > 0 else '['}]"
table.add_row([self.name, array_entry, self.data_range, self.simulation_range])
return table.get_string()

Expand Down
6 changes: 3 additions & 3 deletions RATapi/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def check_layers(cls, value: ClassList, info: ValidationInfo):
if not all(isinstance(element, model) for element in value):
raise ValueError(
f'"The layers attribute contains {other_model}s, '
f'but the absorption parameter is {info.data["absorption"]}. '
f"but the absorption parameter is {info.data['absorption']}. "
f'The attribute should be a ClassList of {model_name} instead."'
)

Expand Down Expand Up @@ -568,15 +568,15 @@ def check_protected_parameters(self) -> "Project":
removed_params = [
param for param in self._protected_parameters[class_list] if param not in protected_parameters
]
raise ValueError(f'Can\'t delete the protected parameters: {", ".join(str(i) for i in removed_params)}')
raise ValueError(f"Can't delete the protected parameters: {', '.join(str(i) for i in removed_params)}")
self._protected_parameters = self.get_all_protected_parameters()
return self

def __str__(self):
output = ""
for key, value in self.__dict__.items():
if value:
output += f'{key.replace("_", " ").title() + ": " :-<100}\n\n'
output += f"{key.replace('_', ' ').title() + ': ':-<100}\n\n"
try:
output += value.value + "\n\n" # For enums
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion RATapi/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def run(project, controls):
end = time.time()

if display_on:
print(f"Elapsed time is {end-start:.3f} seconds\n")
print(f"Elapsed time is {end - start:.3f} seconds\n")

results = make_results(controls.procedure, output_results, bayes_results)

Expand Down
2 changes: 1 addition & 1 deletion RATapi/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def plot_ref_sld_helper(

# Plot the slds on plot (1,2)
for j in range(len(sld)):
label = name if len(sld) == 1 else f"{name} Domain {j+1}"
label = name if len(sld) == 1 else f"{name} Domain {j + 1}"
sld_plot.plot(sld[j][:, 0], sld[j][:, 1], label=label, linewidth=1)

# Plot confidence intervals if required
Expand Down
40 changes: 20 additions & 20 deletions tests/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def test_initialise_non_calculate_properties(self, wrong_property: str, value: A
UserWarning,
match=f'\nThe current controls procedure is "calculate", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "calculate" controls procedure are:\n'
f' {", ".join(fields["calculate"])}\n',
f" {', '.join(fields['calculate'])}\n",
):
Controls(procedure=Procedures.Calculate, **{wrong_property: value})

Expand Down Expand Up @@ -171,9 +171,9 @@ def test_set_non_calculate_properties(self, wrong_property: str, value: Any) ->
UserWarning,
match=f'\nThe current controls procedure is "calculate", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "calculate" controls procedure are:\n'
f' {", ".join(fields["calculate"])}\n',
f" {', '.join(fields['calculate'])}\n",
):
setattr(self.calculate, wrong_property, value)

Expand Down Expand Up @@ -301,9 +301,9 @@ def test_initialise_non_simplex_properties(self, wrong_property: str, value: Any
UserWarning,
match=f'\nThe current controls procedure is "simplex", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "simplex" controls procedure are:\n'
f' {", ".join(fields["simplex"])}\n',
f" {', '.join(fields['simplex'])}\n",
):
Controls(procedure=Procedures.Simplex, **{wrong_property: value})

Expand Down Expand Up @@ -334,9 +334,9 @@ def test_set_non_simplex_properties(self, wrong_property: str, value: Any) -> No
UserWarning,
match=f'\nThe current controls procedure is "simplex", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "simplex" controls procedure are:\n'
f' {", ".join(fields["simplex"])}\n',
f" {', '.join(fields['simplex'])}\n",
):
setattr(self.simplex, wrong_property, value)

Expand Down Expand Up @@ -458,9 +458,9 @@ def test_initialise_non_de_properties(self, wrong_property: str, value: Any) ->
UserWarning,
match=f'\nThe current controls procedure is "de", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "de" controls procedure are:\n'
f' {", ".join(fields["de"])}\n',
f" {', '.join(fields['de'])}\n",
):
Controls(procedure=Procedures.DE, **{wrong_property: value})

Expand Down Expand Up @@ -489,9 +489,9 @@ def test_set_non_de_properties(self, wrong_property: str, value: Any) -> None:
UserWarning,
match=f'\nThe current controls procedure is "de", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "de" controls procedure are:\n'
f' {", ".join(fields["de"])}\n',
f" {', '.join(fields['de'])}\n",
):
setattr(self.de, wrong_property, value)

Expand Down Expand Up @@ -627,9 +627,9 @@ def test_initialise_non_ns_properties(self, wrong_property: str, value: Any) ->
UserWarning,
match=f'\nThe current controls procedure is "ns", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "ns" controls procedure are:\n'
f' {", ".join(fields["ns"])}\n',
f" {', '.join(fields['ns'])}\n",
):
Controls(procedure=Procedures.NS, **{wrong_property: value})

Expand Down Expand Up @@ -662,9 +662,9 @@ def test_set_non_ns_properties(self, wrong_property: str, value: Any) -> None:
UserWarning,
match=f'\nThe current controls procedure is "ns", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "ns" controls procedure are:\n'
f' {", ".join(fields["ns"])}\n',
f" {', '.join(fields['ns'])}\n",
):
setattr(self.ns, wrong_property, value)

Expand Down Expand Up @@ -797,9 +797,9 @@ def test_initialise_non_dream_properties(self, wrong_property: str, value: Any)
UserWarning,
match=f'\nThe current controls procedure is "dream", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "dream" controls procedure are:\n'
f' {", ".join(fields["dream"])}\n',
f" {', '.join(fields['dream'])}\n",
):
Controls(procedure=Procedures.DREAM, **{wrong_property: value})

Expand Down Expand Up @@ -830,9 +830,9 @@ def test_set_non_dream_properties(self, wrong_property: str, value: Any) -> None
UserWarning,
match=f'\nThe current controls procedure is "dream", but the property'
f' "{wrong_property}" applies instead to the'
f' {", ".join(incorrect_procedures)} procedure.\n\n'
f" {', '.join(incorrect_procedures)} procedure.\n\n"
f' The fields for the "dream" controls procedure are:\n'
f' {", ".join(fields["dream"])}\n',
f" {', '.join(fields['dream'])}\n",
):
setattr(self.dream, wrong_property, value)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def dspc_bilayer():
param = project.background_parameters[i]
for background in project.backgrounds:
if background.value_1 == param.name:
background.value_1 = f"Background parameter {i+1}"
param.name = f"Background parameter {i+1}"
background.value_1 = f"Background parameter {i + 1}"
param.name = f"Background parameter {i + 1}"

for i in range(0, len(project.resolution_parameters)):
param = project.resolution_parameters[i]
for resolution in project.resolutions:
if resolution.value_1 == param.name:
resolution.value_1 = f"Resolution parameter {i+1}"
param.name = f"Resolution parameter {i+1}"
resolution.value_1 = f"Resolution parameter {i + 1}"
param.name = f"Resolution parameter {i + 1}"

return project

Expand Down
24 changes: 12 additions & 12 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_initialise_with_wrong_type(self, model: Callable, model_params: dict) -
"""When initialising a model with the wrong type for the "name" field, we should raise a ValidationError."""
with pytest.raises(
pydantic.ValidationError,
match=f"1 validation error for {model.__name__}\nname\n " f"Input should be a valid string",
match=f"1 validation error for {model.__name__}\nname\n Input should be a valid string",
):
model(name=1, **model_params)

Expand All @@ -79,23 +79,23 @@ def test_assignment_with_wrong_type(self, model: Callable, model_params: dict) -
test_model = model(**model_params)
with pytest.raises(
pydantic.ValidationError,
match=f"1 validation error for {model.__name__}\nname\n " f"Input should be a valid string",
match=f"1 validation error for {model.__name__}\nname\n Input should be a valid string",
):
test_model.name = 1

def test_initialise_with_zero_length_name(self, model: Callable, model_params: dict) -> None:
"""When initialising a model with a zero length name, we should raise a ValidationError."""
with pytest.raises(
pydantic.ValidationError,
match=f"1 validation error for {model.__name__}\nname\n " f"String should have at least 1 character",
match=f"1 validation error for {model.__name__}\nname\n String should have at least 1 character",
):
model(name="", **model_params)

def test_initialise_with_extra_fields(self, model: Callable, model_params: dict) -> None:
"""When initialising a model with unspecified fields, we should raise a ValidationError."""
with pytest.raises(
pydantic.ValidationError,
match=f"1 validation error for {model.__name__}\nnew_field\n " f"Extra inputs are not permitted",
match=f"1 validation error for {model.__name__}\nnew_field\n Extra inputs are not permitted",
):
model(new_field=1, **model_params)

Expand Down Expand Up @@ -134,7 +134,7 @@ def test_data_too_few_dimensions(input_data: np.ndarray[float]) -> None:
"""
with pytest.raises(
pydantic.ValidationError,
match='1 validation error for Data\ndata\n Value error, "data" must ' "have at least two dimensions",
match='1 validation error for Data\ndata\n Value error, "data" must have at least two dimensions',
):
RATapi.models.Data(data=input_data)

Expand All @@ -153,7 +153,7 @@ def test_data_too_few_values(input_data: np.ndarray[float]) -> None:
"""
with pytest.raises(
pydantic.ValidationError,
match='1 validation error for Data\ndata\n Value error, "data" must ' "have at least three columns",
match='1 validation error for Data\ndata\n Value error, "data" must have at least three columns',
):
RATapi.models.Data(data=input_data)

Expand Down Expand Up @@ -184,9 +184,9 @@ def test_two_values_in_data_range(input_range: list[float]) -> None:
"""
with pytest.raises(
pydantic.ValidationError,
match=f'1 validation error for Data\ndata_range\n List should have '
f'at {"least" if len(input_range) < 2 else "most"} 2 items '
f'after validation, not {len(input_range)}',
match=f"1 validation error for Data\ndata_range\n List should have "
f"at {'least' if len(input_range) < 2 else 'most'} 2 items "
f"after validation, not {len(input_range)}",
):
RATapi.models.Data(data_range=input_range)

Expand All @@ -205,9 +205,9 @@ def test_two_values_in_simulation_range(input_range: list[float]) -> None:
"""
with pytest.raises(
pydantic.ValidationError,
match=f'1 validation error for Data\nsimulation_range\n List should '
f'have at {"least" if len(input_range) < 2 else "most"} 2 items '
f'after validation, not {len(input_range)}',
match=f"1 validation error for Data\nsimulation_range\n List should "
f"have at {'least' if len(input_range) < 2 else 'most'} 2 items "
f"after validation, not {len(input_range)}",
):
RATapi.models.Data(simulation_range=input_range)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def test_assign_models(test_project, field: str, model_params: dict) -> None:
input_model = model_classes[field]
with pytest.raises(
pydantic.ValidationError,
match=f"1 validation error for Project\n{field}\n Input should be " f"an instance of ClassList",
match=f"1 validation error for Project\n{field}\n Input should be an instance of ClassList",
):
setattr(test_project, field, input_model(**model_params))

Expand Down Expand Up @@ -865,7 +865,7 @@ def test_allowed_contrast_models(
"""
with pytest.raises(
pydantic.ValidationError,
match=f'1 validation error for Project\n Value error, The values: '
match=f"1 validation error for Project\n Value error, The values: "
f'"{", ".join(test_contrast.model)}" in the "model" field of '
f'"contrasts" must be defined in "{field_name}".',
):
Expand Down Expand Up @@ -1036,7 +1036,7 @@ def test_check_allowed_background_resolution_values_on_data_list(test_value: str
)
with pytest.raises(
ValueError,
match=f'The value "{test_value}" in the "value_1" field of "backgrounds" must be ' f'defined in "data".',
match=f'The value "{test_value}" in the "value_1" field of "backgrounds" must be defined in "data".',
):
project.check_allowed_background_resolution_values(
"backgrounds", ["value_1"], ["Background Param 1"], ["Simulation"]
Expand Down

0 comments on commit 082657c

Please sign in to comment.