Skip to content

Commit

Permalink
fix: Fix mutable defaults and missing asserts in code (#3492)
Browse files Browse the repository at this point in the history
* fix: Fix mutable defaults and missing asserts in code

* feat: Add test
  • Loading branch information
mkundu1 authored Nov 18, 2024
1 parent 09bc6a1 commit 439b49d
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ repos:
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear==24.10.31]
args: [
--exclude, src/ansys/fluent/core/generated,
--count,
--statistics,
--max-complexity, "10",
--max-line-length, "88",
--extend-ignore, E203 E501 C901,
--extend-ignore, E203 E501 C901 B007 B009 B010 B011 B028,
src, doc, examples, tests
]

Expand Down
4 changes: 3 additions & 1 deletion doc/settings_rstgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def _get_indent_str(indent):
return f"{' '*indent*4}"


def _generate_table_for_rst(r, data_dict={}):
def _generate_table_for_rst(r, data_dict=None):
if data_dict is None:
data_dict = {}
# Get dimensions for columns
key_max = len(max(data_dict.keys(), key=len))
val_max = len(max(data_dict.values(), key=len))
Expand Down
4 changes: 3 additions & 1 deletion src/ansys/fluent/core/scheduler/machine_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ def core_list(self):
class MachineList(object):
"""Provides an interface to list of machines allocated by a queue system."""

def __init__(self, machinesIn=[]):
def __init__(self, machinesIn=None):
"""Constructs and initializes an empty machine file object."""
if machinesIn is None:
machinesIn = []
self._machines = []
for machine in machinesIn:
self._machines.append(machine)
Expand Down
4 changes: 3 additions & 1 deletion src/ansys/fluent/core/services/deprecated_field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def get_pathlines_field_data(
tolerance: float | None = 0.001,
coarsen: int | None = 1,
velocity_domain: str | None = "all-phases",
zones: list = [],
zones: list | None = None,
) -> Dict:
"""Get the pathlines field data on a surface.
Expand Down Expand Up @@ -624,6 +624,8 @@ def get_pathlines_field_data(
Dictionary containing a map of surface IDs to the pathline data.
For example, pathlines connectivity, vertices, and field.
"""
if zones is None:
zones = []
warnings.warn(DEPRECATION_MSG, PyFluentDeprecationWarning)
surface_ids = _get_surface_ids(
field_info=self._field_info,
Expand Down
8 changes: 6 additions & 2 deletions src/ansys/fluent/core/services/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def add_pathlines_fields_request(
tolerance: float | None = 0.001,
coarsen: int | None = 1,
velocity_domain: str | None = "all-phases",
zones: list = [],
zones: list | None = None,
) -> None:
"""Add request to get pathlines field on surfaces.
Expand Down Expand Up @@ -655,6 +655,8 @@ def add_pathlines_fields_request(
-------
None
"""
if zones is None:
zones = []
surface_ids = _get_surface_ids(
field_info=self._field_info,
allowed_surface_names=self._allowed_surface_names,
Expand Down Expand Up @@ -1191,7 +1193,7 @@ def get_pathlines_field_data(
tolerance: float | None = 0.001,
coarsen: int | None = 1,
velocity_domain: str | None = "all-phases",
zones: list = [],
zones: list | None = None,
) -> Dict:
"""Get the pathlines field data on a surface.
Expand Down Expand Up @@ -1233,6 +1235,8 @@ def get_pathlines_field_data(
Dictionary containing a map of surface IDs to the pathline data.
For example, pathlines connectivity, vertices, and field.
"""
if zones is None:
zones = []
surface_ids = _get_surface_ids(
field_info=self._field_info,
allowed_surface_names=self._allowed_surface_names,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_casereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def test_lispy_for_multiline_string():


def test_lispy_for_quotes():
lispy.parse(
assert lispy.parse(
'(define x "\n(format \\"\n-------------------------\nRunning Original Settings\n------------------------\n\\")")'
) == [
"define",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_field_data_objects_3d(new_solver_session) -> None:
data_types=[SurfaceDataType.FacesNormal], surfaces=[3, 5]
)
assert faces_normal_data[3][SurfaceDataType.FacesNormal].shape == (152, 3)
faces_normal_data[5][SurfaceDataType.FacesNormal].shape == (2001, 3)
assert faces_normal_data[5][SurfaceDataType.FacesNormal].shape == (2001, 3)

faces_connectivity_data = field_data.get_surface_data(
data_types=[SurfaceDataType.FacesConnectivity], surfaces=["cold-inlet"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def test_attrs():
r.g_1.b_3 = True
assert not r.g_1.s_4.get_attr("active?")
with pytest.raises(InactiveObjectError):
r.g_1.s_4.get_attr("allowed-values") == ["foo", "bar"]
r.g_1.s_4.get_attr("allowed-values")


# The following test is commented out as codegen module is not packaged in the
Expand Down
2 changes: 1 addition & 1 deletion tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def test_fluent_enums():
with pytest.raises(ValueError):
UIMode("")
with pytest.raises(TypeError):
UIMode.NO_GUI < FluentWindowsGraphicsDriver.AUTO
assert UIMode.NO_GUI < FluentWindowsGraphicsDriver.AUTO


def test_exposure_and_graphics_driver_arguments():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_solver_preferences(new_solver_session):
preferred_drawing.FacetLimit = 6000000
assert preferred_drawing.FacetLimit() == 6000000
preferred_drawing.FaceZoneLimit = 15000
preferred_drawing.FaceZoneLimit() == 15000
assert preferred_drawing.FaceZoneLimit() == 15000

ansys_logo = solver.preferences.Appearance.AnsysLogo
ansys_logo.Color = "white"
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_meshing_preferences(new_meshing_session):
assert preferred_drawing.FacetLimit() == 6000000

preferred_drawing.FaceZoneLimit = 15000
preferred_drawing.FaceZoneLimit() == 15000
assert preferred_drawing.FaceZoneLimit() == 15000

ansys_logo = meshing.preferences.Appearance.AnsysLogo
ansys_logo.Color = "white"
Expand Down
6 changes: 5 additions & 1 deletion tests/test_settings_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
_OutputFile,
to_python_name,
)
from ansys.fluent.core.utils.execution import timeout_loop
from ansys.fluent.core.utils.fluent_version import FluentVersion
from ansys.fluent.core.warnings import PyFluentUserWarning

Expand Down Expand Up @@ -212,7 +213,10 @@ def test_api_upgrade(new_solver_session, capsys):
solver = new_solver_session
case_path = download_file("Static_Mixer_main.cas.h5", "pyfluent/static_mixer")
solver.tui.file.read_case(case_path)
"<solver_session>.file.read_case" in capsys.readouterr().out
timeout_loop(
lambda: "<solver_session>.settings.file.read_case" in capsys.readouterr().out,
timeout=5,
)


# Custom aliases are not tested with 25.1 or later due to conflicts with the actual aliases
Expand Down

0 comments on commit 439b49d

Please sign in to comment.