Skip to content

Commit 936140a

Browse files
EntList Integration Tests (#34)
* EntList Integration Tests * Update tests/api/integration_tests/test_integration_ent_list.py Co-authored-by: Copilot <[email protected]> * SelectFromSavedList function test * Refactoring for new infra * SavedList tests * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent bb1f666 commit 936140a

File tree

11 files changed

+242
-1
lines changed

11 files changed

+242
-1
lines changed

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ markers =
77
json_file_name(file_name): Mark test to use a specific JSON file for expected data
88
cad_manager: Tests the CADManager class
99
double_array: Tests the DoubleArray class
10+
ent_list: Tests the EntList class
1011
import_options: Tests the ImportOptions class
1112
integer_array: Tests the IntegerArray class
1213
mesh_summary: Tests the MeshSummary class

tests/api/integration_tests/metadata.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@
2222
"time": "06:58:32 UTC",
2323
"build_number": "49.1.198",
2424
"version": "2026"
25+
},
26+
"ent_list": {
27+
"date": "2025-12-02",
28+
"time": "15:34:24 UTC",
29+
"build_number": "49.1.198",
30+
"version": "2026"
2531
}
2632
}
Binary file not shown.
Binary file not shown.

tests/api/integration_tests/study_files/project_meshed_studies/meshed_studies.mpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ END PROJECT
77
ORGANIZE 0
88
BEGIN PROPERTIES
99
END PROPERTIES
10-
Last Write Time: Thu Nov 6 18:28:23 2025
10+
Last Write Time: Tue Dec 2 21:18:16 2025
1111

Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2025 Autodesk, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""
5+
Constants for entity list tests.
6+
"""
7+
8+
TEST_ENTITY_LIST_ITEMS = {
9+
"dd_model": {"entity_type": "T", "items": [56, 57], "saved_list_name": "MyTest"},
10+
"midplane_model": {"entity_type": "T", "items": [56, 57], "saved_list_name": "MyTest"},
11+
"3d_model": {"entity_type": "TE", "items": [3798, 3799], "saved_list_name": "MyTest"},
12+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"3d_model": {
3+
"item_string": "TE3798 TE3799",
4+
"item_predicate": "TE3798:3799",
5+
"saved_list_name": "MyTest",
6+
"converted_string": "TE3798 TE3799 ",
7+
"size": 2,
8+
"entity": {
9+
"0": "TE3798 ",
10+
"1": "TE3799 "
11+
}
12+
},
13+
"dd_model": {
14+
"item_string": "T56 T57",
15+
"item_predicate": "T56:57",
16+
"saved_list_name": "MyTest",
17+
"converted_string": "T56 T57 ",
18+
"size": 2,
19+
"entity": {
20+
"0": "T56 ",
21+
"1": "T57 "
22+
}
23+
},
24+
"midplane_model": {
25+
"item_string": "T56 T57",
26+
"item_predicate": "T56:57",
27+
"saved_list_name": "MyTest",
28+
"converted_string": "T56 T57 ",
29+
"size": 2,
30+
"entity": {
31+
"0": "T56 ",
32+
"1": "T57 "
33+
}
34+
}
35+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: 2025 Autodesk, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""
5+
Generate data for a new property.
6+
Returns a dict with relevant properties.
7+
"""
8+
9+
from moldflow import Synergy
10+
from tests.api.integration_tests.data_generation.generate_data_helper import generate_json
11+
from tests.api.integration_tests.constants import FileSet
12+
from tests.api.integration_tests.test_suite_ent_list.constants import TEST_ENTITY_LIST_ITEMS
13+
14+
15+
@generate_json(file_set=FileSet.MESHED)
16+
def generate_ent_list_data(synergy: Synergy, study_file: str):
17+
"""
18+
Generates expected test data for EntList integration tests based on the entity type and items
19+
specified in the study file. Returns a dictionary with properties such as item strings,
20+
predicates, saved list name, converted string, size, and entity mapping for use in tests.
21+
"""
22+
entity_type = TEST_ENTITY_LIST_ITEMS[study_file]["entity_type"]
23+
items = TEST_ENTITY_LIST_ITEMS[study_file]["items"]
24+
saved_list_name = TEST_ENTITY_LIST_ITEMS[study_file]["saved_list_name"]
25+
26+
item_string = " ".join([f"{entity_type}{item}" for item in items])
27+
item_predicate = f"{entity_type}{items[0]}:{items[1]}"
28+
converted_string = f"{item_string} "
29+
size = len(items)
30+
entity = {i: f"{entity_type}{item} " for i, item in enumerate(items)}
31+
32+
return {
33+
"item_string": item_string,
34+
"item_predicate": item_predicate,
35+
"saved_list_name": saved_list_name,
36+
"converted_string": converted_string,
37+
"size": size,
38+
"entity": entity,
39+
}
40+
41+
42+
if __name__ == "__main__":
43+
generate_ent_list_data()
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# SPDX-FileCopyrightText: 2025 Autodesk, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""
5+
Integration tests for EntList Wrapper Class of moldflow-api module.
6+
7+
These tests focus on testing the actual functionality and behavior
8+
of the EntList class with real Moldflow Synergy COM objects.
9+
"""
10+
11+
import pytest
12+
from moldflow import EntList, Synergy
13+
from tests.api.integration_tests.constants import FileSet
14+
15+
16+
TEST_ENTITY_LIST_PARAMETERS = [
17+
("select_from_string", "item_string"),
18+
("select_from_predicate", "item_predicate"),
19+
("select_from_saved_list", "saved_list_name"),
20+
]
21+
22+
23+
@pytest.mark.integration
24+
@pytest.mark.ent_list
25+
@pytest.mark.file_set(FileSet.MESHED)
26+
class TestIntegrationEntList:
27+
"""
28+
Integration test suite for the EntList class.
29+
"""
30+
31+
@pytest.fixture
32+
def ent_list(self, synergy: Synergy, study_with_project):
33+
"""
34+
Fixture to create a real EntList instance for integration testing.
35+
"""
36+
study_doc = synergy.study_doc
37+
return study_doc.create_entity_list()
38+
39+
def _select_entities(
40+
self,
41+
synergy: Synergy,
42+
ent_list: EntList,
43+
study_file,
44+
select_function,
45+
parameter,
46+
values_to_select,
47+
):
48+
"""
49+
Select entities from the entity list.
50+
"""
51+
if select_function == "select_from_string":
52+
getattr(ent_list, select_function)(values_to_select[parameter])
53+
elif select_function == "select_from_predicate":
54+
pm = synergy.predicate_manager
55+
predicate = pm.create_label_predicate(values_to_select[parameter])
56+
getattr(ent_list, select_function)(predicate)
57+
elif select_function == "select_from_saved_list":
58+
getattr(ent_list, select_function)(values_to_select[parameter])
59+
else:
60+
raise ValueError(f"Invalid select function: {select_function}")
61+
62+
def test_entity_list(self, ent_list: EntList):
63+
"""
64+
Test the entity list method of EntList.
65+
"""
66+
assert ent_list.size == 0
67+
assert ent_list.convert_to_string() == ""
68+
69+
@pytest.mark.parametrize(
70+
"select_function, parameter",
71+
TEST_ENTITY_LIST_PARAMETERS,
72+
ids=["select_from_string", "select_from_predicate", "select_from_saved_list"],
73+
)
74+
def test_entity_list_size(
75+
self,
76+
synergy: Synergy,
77+
ent_list: EntList,
78+
study_file,
79+
select_function,
80+
parameter,
81+
expected_values,
82+
):
83+
"""
84+
Test the size property of EntList.
85+
"""
86+
assert ent_list.size == 0
87+
self._select_entities(
88+
synergy, ent_list, study_file, select_function, parameter, expected_values
89+
)
90+
assert ent_list.size == expected_values["size"]
91+
92+
@pytest.mark.parametrize(
93+
"select_function, parameter",
94+
TEST_ENTITY_LIST_PARAMETERS,
95+
ids=["select_from_string", "select_from_predicate", "select_from_saved_list"],
96+
)
97+
def test_entity_list_convert_to_string(
98+
self,
99+
synergy: Synergy,
100+
ent_list: EntList,
101+
study_file,
102+
select_function,
103+
parameter,
104+
expected_values,
105+
):
106+
"""
107+
Test the convert_to_string method of EntList.
108+
"""
109+
self._select_entities(
110+
synergy, ent_list, study_file, select_function, parameter, expected_values
111+
)
112+
assert ent_list.convert_to_string() == expected_values["converted_string"]
113+
114+
@pytest.mark.parametrize(
115+
"select_function, parameter",
116+
TEST_ENTITY_LIST_PARAMETERS,
117+
ids=["select_from_string", "select_from_predicate", "select_from_saved_list"],
118+
)
119+
def test_entity_list_entity(
120+
self,
121+
synergy: Synergy,
122+
ent_list: EntList,
123+
study_file,
124+
select_function,
125+
parameter,
126+
expected_values,
127+
):
128+
"""
129+
Test the entity method of EntList.
130+
"""
131+
self._select_entities(
132+
synergy, ent_list, study_file, select_function, parameter, expected_values
133+
)
134+
for i in range(ent_list.size):
135+
assert ent_list.entity(i).convert_to_string() == expected_values["entity"][str(i)]
136+
137+
def test_entity_list_select_from_predicate_none(self, ent_list: EntList):
138+
"""
139+
Test the select_from_predicate method of EntList with None parameter.
140+
"""
141+
ent_list.select_from_predicate(None)
142+
assert ent_list.size == 0
143+
assert ent_list.convert_to_string() == ""

0 commit comments

Comments
 (0)