@@ -21,11 +21,16 @@ class FluentRuntimeError(RuntimeError):
2121 pass
2222
2323
24- def run_fluent_test (journal_file : Path , launcher_args : str = "" ) -> None :
24+ def run_fluent_test (
25+ src_test_dir : Path , journal_file : Path , launcher_args : str = ""
26+ ) -> None :
2527 """Run Fluent test.
2628
2729 Parameters
2830 ----------
31+ src_test_dir : Path
32+ Path to the Fluent test directory in the host.
33+
2934 journal_file : Path
3035 Absolute path to the journal file.
3136
@@ -41,12 +46,27 @@ def run_fluent_test(journal_file: Path, launcher_args: str = "") -> None:
4146 src_pyfluent_dir = str (Path (pyfluent .__file__ ).parent )
4247 verion_for_file_name = FluentVersion .current_dev ().number
4348 dst_pyfluent_dir = f"/ansys_inc/v{ verion_for_file_name } /commonfiles/CPython/3_10/linx64/Release/python/lib/python3.10/site-packages/ansys/fluent/core"
44- src_test_dir = str (journal_file .parent )
49+ src_gen_dir = (
50+ Path (pyfluent .__file__ ).parent / "ansys" / "fluent" / "core" / "generated"
51+ )
52+ dst_gen_dir = f"/ansys_inc/v{ verion_for_file_name } /fluent/fluent{ FluentVersion .current_dev ()!r} /cortex/pylib/flapi/generated"
4553 dst_test_dir = "/testing"
54+ working_dir = Path (dst_test_dir )
55+ parent = journal_file .parent
56+ parents = []
57+ while parent != src_test_dir :
58+ parents .append (parent .name )
59+ parent = parent .parent
60+ parents .reverse ()
61+ for parent in parents :
62+ working_dir /= parent
63+ working_dir = str (working_dir )
64+ src_test_dir = str (src_test_dir )
4665 logging .debug (f"src_pyfluent_dir: { src_pyfluent_dir } " )
4766 logging .debug (f"dst_pyfluent_dir: { dst_pyfluent_dir } " )
4867 logging .debug (f"src_test_dir: { src_test_dir } " )
4968 logging .debug (f"dst_test_dir: { dst_test_dir } " )
69+ logging .debug (f"working_dir: { working_dir } " )
5070
5171 docker_client = docker .from_env ()
5272 version_for_image_tag = FluentVersion .current_dev ().docker_image_tag
@@ -55,34 +75,39 @@ def run_fluent_test(journal_file: Path, launcher_args: str = "") -> None:
5575 image = image_name ,
5676 volumes = [
5777 f"{ src_pyfluent_dir } :{ dst_pyfluent_dir } " ,
78+ f"{ src_gen_dir } :{ dst_gen_dir } " , # Try removing this after pyfluent is updated in commonfiles
5879 f"{ src_test_dir } :{ dst_test_dir } " ,
5980 ],
60- working_dir = dst_test_dir ,
81+ working_dir = working_dir ,
6182 environment = {"ANSYSLMD_LICENSE_FILE" : os .environ ["ANSYSLMD_LICENSE_FILE" ]},
62- command = f"3ddp { launcher_args } -gu -py -i { journal_file .name } " ,
83+ command = f"{ launcher_args } -gu -py -i { journal_file .name } " ,
6384 detach = True ,
6485 stdout = True ,
6586 stderr = True ,
87+ auto_remove = True ,
6688 )
67- while True :
68- container .reload ()
69- if container .status == "exited" :
70- break
71- stderr = container .logs (stdout = False , stderr = True )
72- if stderr :
73- stderr = stderr .decode ()
74- for line in stderr .split ("\n " ):
75- if line .strip ().startswith ("Error:" ):
76- if "Expected exception" in line : # for check_assert.py
77- container .stop ()
78- else :
79- raise FluentRuntimeError (line )
80- sleep (1 )
81- logging .debug (container .logs (stderr = True ).decode ())
82- container .remove ()
83-
84-
85- MAX_TEST_PATH_LENGTH = 40
89+ try :
90+ while True :
91+ container .reload ()
92+ if container .status == "exited" :
93+ break
94+ stderr = container .logs (stdout = False , stderr = True )
95+ if stderr :
96+ stderr = stderr .decode ()
97+ for line in stderr .split ("\n " ):
98+ if line .strip ().startswith ("Error:" ):
99+ if "Expected exception" in line : # for check_assert.py
100+ container .stop ()
101+ else :
102+ raise FluentRuntimeError (line )
103+ sleep (1 )
104+ logging .debug (container .logs (stderr = True ).decode ())
105+ container .remove ()
106+ except docker .errors .NotFound :
107+ pass
108+
109+
110+ MAX_TEST_PATH_LENGTH = 100
86111
87112
88113if __name__ == "__main__" :
@@ -93,19 +118,20 @@ def run_fluent_test(journal_file: Path, launcher_args: str = "") -> None:
93118 )
94119 args = parser .parse_args ()
95120 test_dir = Path .cwd () / args .test_dir
96- with TemporaryDirectory (ignore_cleanup_errors = True ) as tmpdir :
97- copytree (test_dir , tmpdir , dirs_exist_ok = True )
121+ with TemporaryDirectory (ignore_cleanup_errors = True ) as src_test_dir :
122+ copytree (test_dir , src_test_dir , dirs_exist_ok = True )
98123 exception_occurred = False
99- for test_file in Path (tmpdir ).rglob ("*.py" ):
124+ src_test_dir = Path (src_test_dir )
125+ for test_file in (src_test_dir / "fluent" ).rglob ("*.py" ):
100126 config_file = test_file .with_suffix (".yaml" )
101127 launcher_args = ""
102128 if config_file .exists ():
103129 configs = yaml .safe_load (config_file .read_text ())
104130 launcher_args = configs .get ("launcher_args" , "" )
105- test_file_relpath = str (test_file .relative_to (tmpdir ))
131+ test_file_relpath = str (test_file .relative_to (src_test_dir ))
106132 print (f"Running { test_file_relpath } " , end = "" , flush = True )
107133 try :
108- run_fluent_test (test_file , launcher_args )
134+ run_fluent_test (src_test_dir , test_file , launcher_args )
109135 print (
110136 f"{ (MAX_TEST_PATH_LENGTH + 10 - len (test_file_relpath )) * '·' } PASSED"
111137 )
0 commit comments