-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_project.py
100 lines (78 loc) · 3.7 KB
/
test_project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import pydantic as pd
import pytest
import flow360 as fl
from flow360 import log
from flow360.exceptions import Flow360ValueError
log.set_logging_level("DEBUG")
@pytest.fixture(autouse=True)
def change_test_dir(request, monkeypatch):
monkeypatch.chdir(request.fspath.dirname)
def test_from_cloud(mock_id, mock_response):
project = fl.Project.from_cloud(project_id="prj-41d2333b-85fd-4bed-ae13-15dcb6da519e")
project.print_project_tree(is_horizontal=True, line_width=15)
assert isinstance(project._root_asset, fl.Geometry)
assert len(project.get_surface_mesh_ids()) == 1
assert len(project.get_volume_mesh_ids()) == 1
assert len(project.get_case_ids()) == 2
current_geometry_id = "geo-2877e124-96ff-473d-864b-11eec8648d42"
current_surface_mesh_id = "sm-1f1f2753-fe31-47ea-b3ab-efb2313ab65a"
current_volume_mesh_id = "vm-7c3681cd-8c6c-4db7-a62c-1742d825e9d3"
current_case_id = "case-84d4604e-f3cd-4c6b-8517-92a80a3346d3"
assert project.geometry.id == current_geometry_id
assert project.surface_mesh.id == current_surface_mesh_id
assert project.volume_mesh.id == current_volume_mesh_id
assert project.case.id == current_case_id
for case_id in project.get_case_ids():
project.project_tree.remove_node(node_id=case_id)
error_msg = "No Case is available in this project."
with pytest.raises(Flow360ValueError, match=error_msg):
project.get_case(asset_id=current_case_id)
def test_get_asset_with_id(mock_id, mock_response):
project = fl.Project.from_cloud(project_id="prj-41d2333b-85fd-4bed-ae13-15dcb6da519e")
print(f"The correct asset_id: {project.case.id}")
query_id = " case-84d4604e-f3cd-4c6b-8517-92a80a3346d3 "
assert project.get_case(asset_id=query_id)
query_id = "=case-84d4604e-f3cd-4c6b-8517-92a80a3346d3&"
assert project.get_case(asset_id=query_id)
query_id = "case"
error_msg = (
r"The supplied ID \(" + query_id + r"\) does not have a proper surffix-ID structure."
)
with pytest.raises(Flow360ValueError, match=error_msg):
project.get_case(asset_id=query_id)
query_id = "sm-123456"
error_msg = r"The input asset ID \(" + query_id + r"\) is not a Case ID."
with pytest.raises(Flow360ValueError, match=error_msg):
project.get_case(asset_id=query_id)
query_id = "case-b0"
error_msg = (
r"The input asset ID \(" + query_id + r"\) is too short to retrieve the correct asset."
)
with pytest.raises(Flow360ValueError, match=error_msg):
project.get_case(asset_id=query_id)
query_id = "case-1234567-abcd"
error_msg = (
r"This asset does not exist in this project. Please check the input asset ID \("
+ query_id
+ r"\)"
)
with pytest.raises(Flow360ValueError, match=error_msg):
project.get_case(asset_id=query_id)
@pytest.mark.usefixtures("s3_download_override")
def test_run(mock_response, capsys):
project = fl.Project.from_cloud(project_id="prj-41d2333b-85fd-4bed-ae13-15dcb6da519e")
parent_case = project.get_case("case-69b8c249")
case = project.case
params = case.params
warning_msg = "The VolumeMesh that matches the input already exists in project. No new VolumeMesh will be generated."
project.generate_volume_mesh(params=params)
captured_text = capsys.readouterr().out
captured_text = " ".join(captured_text.split())
assert warning_msg in captured_text
warning_msg = (
"The Case that matches the input already exists in project. No new Case will be generated."
)
project.run_case(params=params, fork_from=parent_case)
captured_text = capsys.readouterr().out
captured_text = " ".join(captured_text.split())
assert warning_msg in captured_text