Skip to content

Commit c4f2e61

Browse files
authored
Fix minimum version required for Unit Systems (#782)
* Unit system functionality was filtered as 6.0 but should be 6.1. * Raise an error when creating a Custom Unit System for a server <6.1 * Fix a circular import.
1 parent 5a92a48 commit c4f2e61

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

src/ansys/dpf/core/unit_system.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
"""
77
from ansys.dpf import core as dpf
88
from ansys.dpf.core import errors as dpf_errors
9+
from ansys.dpf.core import server as server_module
910

1011

1112
class UnitSystem:
12-
"""Defines an internally coherent way of measuring units."""
13+
"""Defines an internally coherent way of measuring units.
14+
15+
Notes
16+
-----
17+
Class available with server's version starting at 6.1 (Ansys 2023R2).
18+
"""
1319

1420
def __init__(self, name, ID=None, unit_names=None):
1521
"""
@@ -41,6 +47,9 @@ def __init__(self, name, ID=None, unit_names=None):
4147
>>> from ansys.dpf import core as dpf
4248
>>> my_unit_system = dpf.UnitSystem("my_mks", unit_names="m;kg;s;degF;C;rad")
4349
"""
50+
server = server_module.get_or_create_server(None)
51+
if server and not server.meet_version("6.1"): # pragma: no cover
52+
raise dpf_errors.DpfVersionNotSupported("6.1")
4453
if not isinstance(name, str):
4554
raise dpf_errors.InvalidTypeError("str", "name")
4655

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ def cyclic_multistage():
210210
return core.examples.download_multi_stage_cyclic_result()
211211

212212

213+
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_1 = meets_version(
214+
get_server_version(core._global_server()), "6.1"
215+
)
213216
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0 = meets_version(
214217
get_server_version(core._global_server()), "6.0"
215218
)

tests/test_lsdyna.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66

77
@pytest.mark.skipif(
8-
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0,
9-
reason="LS-DYNA source operators where not supported before 0.6",
8+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_1,
9+
reason="LS-DYNA source operators where not supported before 6.0,"
10+
" and unit systems where not supported before 6.1.",
1011
)
1112
def test_lsdyna_generic(d3plot_files):
1213
ds = dpf.DataSources()
@@ -139,8 +140,9 @@ def test_lsdyna_generic(d3plot_files):
139140

140141

141142
@pytest.mark.skipif(
142-
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0,
143-
reason="LS-DYNA source operators where not supported before 0.6",
143+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_1,
144+
reason="LS-DYNA source operators where not supported before 6.0,"
145+
" and unit systems where not supported before 6.1.",
144146
)
145147
def test_lsdyna_beam(d3plot_beam):
146148
ds = dpf.DataSources()
@@ -313,8 +315,9 @@ def test_lsdyna_beam(d3plot_beam):
313315

314316

315317
@pytest.mark.skipif(
316-
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0,
317-
reason="LS-DYNA source operators where not supported before 0.6",
318+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_1,
319+
reason="LS-DYNA source operators where not supported before 6.0,"
320+
" and unit systems where not supported before 6.1.",
318321
)
319322
def test_lsdyna_matsum_rcforc(binout_matsum):
320323
ds = dpf.DataSources()
@@ -497,7 +500,7 @@ def test_lsdyna_matsum_rcforc(binout_matsum):
497500

498501
@pytest.mark.skipif(
499502
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0,
500-
reason="LS-DYNA source operators where not supported before 0.6",
503+
reason="LS-DYNA source operators where not supported before 6.0",
501504
)
502505
def test_lsdyna_glstat(binout_glstat):
503506
ds = dpf.DataSources()

tests/test_unit_systems.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77
@pytest.mark.skipif(
8-
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0,
9-
reason="unit systems where not supported before 0.6",
8+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_1,
9+
reason="Unit systems where not supported before 6.1.",
1010
)
1111
def test_predefined_unit_systems():
1212
# Test IDs of the predefined ones
@@ -30,8 +30,8 @@ def test_predefined_unit_systems():
3030

3131

3232
@pytest.mark.skipif(
33-
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0,
34-
reason="unit systems where not supported before 0.6",
33+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_1,
34+
reason="Unit systems where not supported before 6.1.",
3535
)
3636
def test_unit_system_api():
3737
# Create custom units from ID

0 commit comments

Comments
 (0)