|
25 | 25 | import os |
26 | 26 | import pathlib |
27 | 27 | import tempfile |
| 28 | +from typing import Any, TypeVar |
28 | 29 |
|
29 | 30 | import numpy as np |
30 | 31 | import numpy.testing |
|
33 | 34 | from ansys.acp.core import ElementalDataType, UnitSystemType |
34 | 35 | from ansys.acp.core.mesh_data import VectorData |
35 | 36 |
|
36 | | -from .helpers import check_property |
| 37 | +T = TypeVar("T") |
37 | 38 |
|
38 | 39 |
|
39 | | -def test_unittest(acp_instance, model_data_dir): |
| 40 | +def _check_property(obj: Any, *, name: str, value: T, set_value: T | None = None): |
| 41 | + assert hasattr(obj, name), f"Object '{obj}' has no property named '{name}'" |
| 42 | + assert ( |
| 43 | + getattr(obj, name) == value |
| 44 | + ), f"Test of property '{name}' failed! value '{getattr( obj, name )}' instead of '{value}'." |
| 45 | + if set_value is not None: |
| 46 | + setattr(obj, name, set_value) |
| 47 | + assert ( |
| 48 | + getattr(obj, name) == set_value |
| 49 | + ), f"Setter of property '{name}' failed! value '{getattr(obj, name)}' instead of '{value}'." |
| 50 | + |
| 51 | + |
| 52 | +def test_unittest(acp_instance, model_data_dir, raises_before_version): |
40 | 53 | """ |
41 | 54 | Test basic properties of the model object |
42 | 55 | """ |
| 56 | + |
43 | 57 | input_file_path = model_data_dir / "ACP-Pre.h5" |
44 | 58 | model = acp_instance.import_model(name="kiteboard", path=input_file_path, format="ansys:h5") |
45 | 59 |
|
46 | | - # TODO: re-activate these tests when the respective features are implemented |
47 | | - # assert model.unit_system.type == "mks" |
48 | | - |
49 | | - check_property(model, name="name", value="kiteboard", set_value="kiteboard_renamed") |
50 | | - # TODO: re-activate these tests when the respective features are implemented |
51 | | - # check_property(model, name="save_path", value="") |
52 | | - # check_property(model, name="format", value="ansys:h5") |
53 | | - # check_property(model, name="cache_update_results", value=True, set_value=False), |
54 | | - # check_property(model, name="path", value=input_file_path), |
55 | | - check_property(model, name="use_nodal_thicknesses", value=False, set_value=True), |
56 | | - check_property(model, name="draping_offset_correction", value=False, set_value=True), |
57 | | - check_property(model, name="angle_tolerance", value=1.0, set_value=2.0), |
58 | | - check_property(model, name="relative_thickness_tolerance", value=0.01, set_value=0.03) |
59 | | - |
60 | | - # TODO: re-activate these tests when the respective features are implemented |
61 | | - # The minimum analysis ply thickness is an absolute value, and depends on the |
62 | | - # unit system being set. This is currently not implemented in PyACP, hence the |
63 | | - # values are wrong (it's not using the expected unit system). |
64 | | - # check_property(model, name="minimum_analysis_ply_thickness", value=1e-09, set_value=2e-09) |
65 | | - # check_property( |
66 | | - # model, |
67 | | - # name="reference_surface_bounding_box", |
68 | | - # value=( |
69 | | - # (-0.6750000000000003, -0.2, 0.0005419999999999998), |
70 | | - # (0.6750000000000003, 0.20000000000000007, 0.0005420000000000003), |
71 | | - # ), |
72 | | - # ) |
| 60 | + _check_property(model, name="name", value="kiteboard", set_value="kiteboard_renamed") |
| 61 | + _check_property(model, name="use_nodal_thicknesses", value=False, set_value=True), |
| 62 | + _check_property(model, name="draping_offset_correction", value=False, set_value=True), |
| 63 | + _check_property(model, name="angle_tolerance", value=1.0, set_value=2.0), |
| 64 | + _check_property(model, name="relative_thickness_tolerance", value=0.01, set_value=0.03) |
| 65 | + with raises_before_version("25.2"): |
| 66 | + _check_property( |
| 67 | + model, name="force_disable_result_extrapolation", value=False, set_value=True |
| 68 | + ) |
73 | 69 |
|
74 | 70 | with tempfile.TemporaryDirectory() as tmp_dir: |
75 | 71 | working_dir = pathlib.Path(tmp_dir) / "workdir" |
76 | 72 | os.makedirs(working_dir) |
77 | | - # model.solver.working_dir = str(working_dir) |
78 | 73 |
|
79 | 74 | with tempfile.TemporaryDirectory() as local_working_dir: |
80 | 75 | save_path = pathlib.Path(local_working_dir) / "test_model_serialization.acph5" |
81 | 76 | model.save(save_path, save_cache=True) |
82 | 77 | acp_instance.clear() |
83 | 78 | model = acp_instance.import_model(path=save_path) |
84 | 79 |
|
85 | | - # TODO: re-activate these tests when the respective features are implemented |
86 | | - # assert model.unit_system.type == "mks" |
87 | | - |
88 | | - check_property(model, name="name", value="kiteboard_renamed") |
89 | | - # TODO: re-activate these tests when the respective features are implemented |
90 | | - # check_property(model, name="save_path", value=save_path) |
91 | | - # check_property(model, name="format", value="ansys:h5") |
92 | | - # check_property(model, name="cache_update_results", value=False) |
93 | | - # check_property(model, name="path", value=input_file_path) |
94 | | - check_property(model, name="use_nodal_thicknesses", value=True) |
95 | | - check_property(model, name="draping_offset_correction", value=True) |
96 | | - check_property(model, name="angle_tolerance", value=2.0) |
97 | | - check_property(model, name="relative_thickness_tolerance", value=0.03) |
98 | | - |
99 | | - # TODO: re-activate these tests when the respective features are implemented |
100 | | - # check_property(model, name="minimum_analysis_ply_thickness", value=2e-09) |
101 | | - # check_property( |
102 | | - # model, |
103 | | - # name="reference_surface_bounding_box", |
104 | | - # value=( |
105 | | - # (-0.6750000000000003, -0.2, 0.0005419999999999998), |
106 | | - # (0.6750000000000003, 0.20000000000000007, 0.0005420000000000003), |
107 | | - # ), |
108 | | - # ) |
109 | | - |
110 | | - # rel_path_posix = pathlib.Path(relpath_if_possible(model.solver.working_dir)).as_posix() |
111 | | - # # To ensure platform independency we store file paths using POSIX format |
112 | | - # assert model.solver.working_dir == rel_path_posix |
| 80 | + _check_property(model, name="name", value="kiteboard_renamed") |
| 81 | + _check_property(model, name="use_nodal_thicknesses", value=True) |
| 82 | + _check_property(model, name="draping_offset_correction", value=True) |
| 83 | + _check_property(model, name="angle_tolerance", value=2.0) |
| 84 | + _check_property(model, name="relative_thickness_tolerance", value=0.03) |
| 85 | + with raises_before_version("25.2"): |
| 86 | + _check_property(model, name="force_disable_result_extrapolation", value=True) |
113 | 87 |
|
114 | 88 |
|
115 | 89 | def test_export_analysis_model(acp_instance, model_data_dir): |
|
0 commit comments