From b5dd926bea8ceb1a474273bd583c2e657afdf656 Mon Sep 17 00:00:00 2001 From: Kei Date: Tue, 5 Nov 2024 19:44:51 +0100 Subject: [PATCH 1/3] add separate visualization in pytest --- tests/test_create_hdf5.py | 60 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/tests/test_create_hdf5.py b/tests/test_create_hdf5.py index 5474a74..7c82428 100644 --- a/tests/test_create_hdf5.py +++ b/tests/test_create_hdf5.py @@ -49,6 +49,21 @@ def test_create_hdf5_solid_only(input_mesh, tmpdir): assert np.isclose(first_time, 2.235075700301419E-9, atol=1e-10) last_time = f["displacement/vector_2"][0] assert np.isclose(last_time, 1.3776599148439903E-8, atol=1e-10) + + # 7. create separate visualization + cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/") + _ = subprocess.check_output(cmd, shell=True) + + # 8. check if the separate visualization exists + velocity_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.h5" + velocity_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.xdmf" + assert velocity_h5_path.exists(), "Separate visualization for velocity does not exist" + assert velocity_xdmf_path.exists(), "Separate visualization for velocity does not exist" + + displacement_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.h5" + displacement_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.xdmf" + assert displacement_h5_path.exists(), "Separate visualization for displacement does not exist" + assert displacement_xdmf_path.exists(), "Separate visualization for displacement does not exist" @pytest.mark.parametrize("input_mesh", [input_data_paths[0]]) @@ -83,6 +98,16 @@ def test_create_hdf5_entire_domain(input_mesh, tmpdir): last_time = f["displacement/vector_2"][0] assert np.isclose(last_time, 1.3776599148439903E-8, atol=1e-10) + # 7. create separate visualization + cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/") + _ = subprocess.check_output(cmd, shell=True) + + # 8. check if the separate visualization exists (only fluid velocity) + velocity_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.h5" + velocity_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.xdmf" + assert velocity_h5_path.exists(), "Separate visualization for velocity does not exist" + assert velocity_xdmf_path.exists(), "Separate visualization for velocity does not exist" + @pytest.mark.parametrize("input_mesh", [input_data_paths[0]]) def test_create_hdf5_with_stride(input_mesh, tmpdir): @@ -123,6 +148,21 @@ def test_create_hdf5_with_stride(input_mesh, tmpdir): assert np.isclose(first_time, 2.235075700301419E-9, atol=1e-10) last_time = f["displacement/vector_1"][0] assert np.isclose(last_time, 1.3776599148439903E-8, atol=1e-10) + + # 7. create separate visualization + cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/") + _ = subprocess.check_output(cmd, shell=True) + + # 8. check if the separate visualization exists + velocity_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.h5" + velocity_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.xdmf" + assert velocity_h5_path.exists(), "Separate visualization for velocity does not exist" + assert velocity_xdmf_path.exists(), "Separate visualization for velocity does not exist" + + displacement_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.h5" + displacement_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.xdmf" + assert displacement_h5_path.exists(), "Separate visualization for displacement does not exist" + assert displacement_xdmf_path.exists(), "Separate visualization for displacement does not exist" @pytest.mark.parametrize("input_mesh", [input_data_paths[0]]) @@ -148,9 +188,9 @@ def test_create_hdf5_with_time(input_mesh, tmpdir): # 5. check if the hdf5 file exists velocity_hdf5_path = tmpdir / "1" / "Visualization_separate_domain" / "u.h5" - assert velocity_hdf5_path.exists() + assert velocity_hdf5_path.exists(), "Velocity hdf5 file does not exist" displacement_hdf5_path = tmpdir / "1" / "Visualization_separate_domain" / "d_solid.h5" - assert displacement_hdf5_path.exists() + assert displacement_hdf5_path.exists(), "Displacement hdf5 file does not exist" # 6. check if the hdf5 file has the correct values with h5py.File(velocity_hdf5_path, "r") as f: @@ -164,3 +204,19 @@ def test_create_hdf5_with_time(input_mesh, tmpdir): assert np.isclose(first_time, 2.235075700301419E-9, atol=1e-10) last_time = f["displacement/vector_1"][0] assert np.isclose(last_time, 7.0569699656660426E-9, atol=1e-10) + + # 7. create separate visualization + cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/") + _ = subprocess.check_output(cmd, shell=True) + + # 8. check if the separate visualization exists + velocity_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.h5" + velocity_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.xdmf" + assert velocity_h5_path.exists(), "Separate visualization for velocity does not exist" + assert velocity_xdmf_path.exists(), "Separate visualization for velocity does not exist" + + displacement_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.h5" + displacement_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.xdmf" + assert displacement_h5_path.exists(), "Separate visualization for displacement does not exist" + assert displacement_xdmf_path.exists(), "Separate visualization for displacement does not exist" + From 3ac540d066739c3d65e79d0b21b2ac5c05b810b8 Mon Sep 17 00:00:00 2001 From: Kei Date: Tue, 5 Nov 2024 19:45:29 +0100 Subject: [PATCH 2/3] rename file --- .../{test_create_hdf5.py => test_create_hdf5_and_separate_viz.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{test_create_hdf5.py => test_create_hdf5_and_separate_viz.py} (100%) diff --git a/tests/test_create_hdf5.py b/tests/test_create_hdf5_and_separate_viz.py similarity index 100% rename from tests/test_create_hdf5.py rename to tests/test_create_hdf5_and_separate_viz.py From f968c95c397a91e75ff604c5888178d5ddc6c84d Mon Sep 17 00:00:00 2001 From: Kei Date: Tue, 5 Nov 2024 19:47:11 +0100 Subject: [PATCH 3/3] address flake8 --- tests/test_create_hdf5_and_separate_viz.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_create_hdf5_and_separate_viz.py b/tests/test_create_hdf5_and_separate_viz.py index 7c82428..c5a331a 100644 --- a/tests/test_create_hdf5_and_separate_viz.py +++ b/tests/test_create_hdf5_and_separate_viz.py @@ -49,7 +49,7 @@ def test_create_hdf5_solid_only(input_mesh, tmpdir): assert np.isclose(first_time, 2.235075700301419E-9, atol=1e-10) last_time = f["displacement/vector_2"][0] assert np.isclose(last_time, 1.3776599148439903E-8, atol=1e-10) - + # 7. create separate visualization cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/") _ = subprocess.check_output(cmd, shell=True) @@ -148,7 +148,7 @@ def test_create_hdf5_with_stride(input_mesh, tmpdir): assert np.isclose(first_time, 2.235075700301419E-9, atol=1e-10) last_time = f["displacement/vector_1"][0] assert np.isclose(last_time, 1.3776599148439903E-8, atol=1e-10) - + # 7. create separate visualization cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/") _ = subprocess.check_output(cmd, shell=True) @@ -204,7 +204,7 @@ def test_create_hdf5_with_time(input_mesh, tmpdir): assert np.isclose(first_time, 2.235075700301419E-9, atol=1e-10) last_time = f["displacement/vector_1"][0] assert np.isclose(last_time, 7.0569699656660426E-9, atol=1e-10) - + # 7. create separate visualization cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/") _ = subprocess.check_output(cmd, shell=True) @@ -219,4 +219,3 @@ def test_create_hdf5_with_time(input_mesh, tmpdir): displacement_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.xdmf" assert displacement_h5_path.exists(), "Separate visualization for displacement does not exist" assert displacement_xdmf_path.exists(), "Separate visualization for displacement does not exist" -