|
21 | 21 | # SOFTWARE. |
22 | 22 |
|
23 | 23 | from os.path import dirname, join |
24 | | -import pathlib |
| 24 | +from pathlib import Path |
25 | 25 | import shutil |
26 | 26 |
|
| 27 | +import defusedxml.ElementTree as ET |
27 | 28 | import pytest |
28 | 29 |
|
29 | 30 | from ansys.fluent.core import examples |
|
34 | 35 | MeshType, |
35 | 36 | _get_processed_string, |
36 | 37 | ) |
| 38 | +from ansys.fluent.core.filereader.case_file import CaseFile |
37 | 39 | from ansys.fluent.core.filereader.case_file import CaseFile as CaseReader |
| 40 | +from ansys.fluent.core.filereader.pre_processor import remove_unsupported_xml_chars |
38 | 41 |
|
39 | 42 |
|
40 | 43 | def call_casereader( |
@@ -145,7 +148,7 @@ def create_dir_structure_locally(copy_1: bool = False, copy_2: bool = False): |
145 | 148 | return_without_path=False, |
146 | 149 | ) |
147 | 150 | prj_dir = join(dirname(case_file_name), case_file_dir) |
148 | | - pathlib.Path(prj_dir).mkdir(parents=True, exist_ok=True) |
| 151 | + Path(prj_dir).mkdir(parents=True, exist_ok=True) |
149 | 152 | if copy_1: |
150 | 153 | shutil.copy2(case_file_name, prj_dir) |
151 | 154 | if copy_2: |
@@ -344,3 +347,39 @@ def test_mesh_reader(): |
344 | 347 | assert mesh_reader_2d.precision() is None |
345 | 348 | assert mesh_reader_3d.precision() is None |
346 | 349 | assert case_reader.precision() == 2 |
| 350 | + |
| 351 | + |
| 352 | +def test_preprocessor(): |
| 353 | + content = """ |
| 354 | + <Project type="object" class="PFolder"> |
| 355 | + <Metadata type="object" class="ansys::Project::MetadataHoof"> |
| 356 | + <ProjectStoragePolicy::FolderEnabled class="string" value="true"/> |
| 357 | + </Metadata> |
| 358 | + </Project> |
| 359 | + """ |
| 360 | + expected = """ |
| 361 | + <Project type="object" class="PFolder"> |
| 362 | + <Metadata type="object" class="ansys::Project::MetadataHoof"> |
| 363 | + <ProjectStoragePolicy__FolderEnabled class="string" value="true"/> |
| 364 | + </Metadata> |
| 365 | + </Project> |
| 366 | + """ |
| 367 | + with pytest.raises(ET.ParseError): |
| 368 | + ET.fromstring(content) |
| 369 | + pre_processed = remove_unsupported_xml_chars(content) |
| 370 | + assert pre_processed == expected |
| 371 | + assert ET.fromstring(pre_processed) |
| 372 | + |
| 373 | + |
| 374 | +def test_read_flprj_3891(): |
| 375 | + # Read the .flprj file from https://github.com/ansys/pyfluent/issues/3891 |
| 376 | + data_zip = examples.download_file( |
| 377 | + "data.zip", |
| 378 | + "pyfluent/flprj_3891", |
| 379 | + return_without_path=False, |
| 380 | + ) |
| 381 | + prj_file_name = next(Path(data_zip).with_suffix("").glob("*.flprj")) |
| 382 | + assert ( |
| 383 | + CaseFile(project_file_name=prj_file_name).get_mesh().get_mesh_type() |
| 384 | + == MeshType.VOLUME |
| 385 | + ) |
0 commit comments