Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHORE: Use matplotlib Agg backend when testing #4702

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions _unittest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tempfile
import time

import matplotlib
import pytest

from pyaedt.generic.settings import settings
Expand Down Expand Up @@ -219,3 +220,9 @@ def _method(project_name=None, subfolder=""):
)

return _method


@pytest.fixture(autouse=True)
def matplotlib_use_agg():
"""Configure Matplotlib to use 'Agg' backend for all tests."""
matplotlib.use("Agg")
5 changes: 2 additions & 3 deletions _unittest/test_02_2D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,14 @@ def test_09_plot(self):
position=[0, 0, 0], start_point=[0, 0, 2], num_sides=3, name="MyPolygon", material="Copper"
)
obj = self.aedtapp.plot(
show=False,
export_path=os.path.join(self.local_scratch.path, "image.jpg"),
show_bounding=True,
show_grid=True,
)
assert os.path.exists(obj.image_file)
obj2 = self.aedtapp.plot(show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy")
obj2 = self.aedtapp.plot(export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy")
assert os.path.exists(obj2.image_file)
obj3 = self.aedtapp.plot(show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy1")
obj3 = self.aedtapp.plot(export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy1")
assert filecmp.cmp(obj.image_file, obj3.image_file)

def test_10_edit_menu_commands(self):
Expand Down
11 changes: 2 additions & 9 deletions _unittest/test_12_1_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def test_01_Animate_plt(self):
intrinsics={"Freq": "5GHz", "Phase": "0deg"},
variation_variable="Phase",
variations=phases,
show=False,
export_gif=True,
export_path=self.local_scratch.path,
)
Expand All @@ -127,7 +126,6 @@ def test_01_Animate_plt(self):
variations=phases,
project_path="",
export_gif=False,
show=False,
)
model_gif2.gif_file = os.path.join(self.aedtapp.working_directory, "test2.gif")
model_gif2.camera_position = [0, 50, 200]
Expand Down Expand Up @@ -514,7 +512,6 @@ def test_14_Field_Ploton_cutplanedesignname(self):
image_format="jpg",
view="xy",
plot_label=plot1.name + " label",
show=False,
)
assert os.path.exists(plot_obj.image_file)
os.unlink(plot_obj.image_file)
Expand All @@ -539,7 +536,6 @@ def test_14_Field_Ploton_cutplanedesignname(self):
image_format="jpg",
view="xy",
plot_label=plot1.name + " label",
show=False,
file_format="aedtplt",
)
assert os.path.exists(plot_obj.image_file)
Expand All @@ -566,20 +562,17 @@ def test_14B_Field_Ploton_Vector(self):
intrinsics=intrinsic,
mesh_on_fields=False,
view="isometric",
show=False,
export_path=self.local_scratch.path,
image_format="jpg",
)
assert os.path.exists(plot_obj.image_file)

@pytest.mark.skipif(is_linux or sys.version_info < (3, 8), reason="Not running in ironpython")
def test_15_export_plot(self):
obj = self.aedtapp.post.plot_model_obj(
show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg")
)
obj = self.aedtapp.post.plot_model_obj(export_path=os.path.join(self.local_scratch.path, "image.jpg"))
assert os.path.exists(obj.image_file)
obj2 = self.aedtapp.post.plot_model_obj(
show=False, export_path=os.path.join(self.local_scratch.path, "image2.jpg"), plot_as_separate_objects=False
export_path=os.path.join(self.local_scratch.path, "image2.jpg"), plot_as_separate_objects=False
)
assert os.path.exists(obj2.image_file)

Expand Down
15 changes: 3 additions & 12 deletions _unittest/test_12_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,14 @@ def test_55_time_plot(self, sbr_test):
)
assert os.path.exists(frames_list)
sbr_test.post.plot_scene(
frames_list, os.path.join(sbr_test.working_directory, "animation.gif"), norm_index=5, dy_rng=35, show=False
frames_list, os.path.join(sbr_test.working_directory, "animation.gif"), norm_index=5, dy_rng=35
)
assert os.path.exists(os.path.join(sbr_test.working_directory, "animation.gif"))
sbr_test.post.plot_scene(
frames_list,
os.path.join(sbr_test.working_directory, "animation2.gif"),
norm_index=5,
dy_rng=35,
show=False,
convert_fields_in_db=True,
log_multiplier=20.0,
)
Expand Down Expand Up @@ -616,14 +615,13 @@ def test_70_far_field_data(self):
ffdata.polar_plot_3d_pyvista(
quantity="RealizedGain",
image_path=img4,
show=False,
background=[255, 0, 0],
show_geometry=False,
convert_to_db=True,
)
assert os.path.exists(img4)
data_pyvista = ffdata.polar_plot_3d_pyvista(
quantity="RealizedGain", show=False, background=[255, 0, 0], show_geometry=False, convert_to_db=True
quantity="RealizedGain", background=[255, 0, 0], show_geometry=False, convert_to_db=True
)
assert isinstance(data_pyvista, Plotter)

Expand All @@ -639,7 +637,6 @@ def test_71_antenna_plot(self, field_test):
title="Contour at {}Hz".format(ffdata.frequency),
image_path=os.path.join(self.local_scratch.path, "contour.jpg"),
convert_to_db=True,
show=False,
)
assert os.path.exists(os.path.join(self.local_scratch.path, "contour.jpg"))

Expand Down Expand Up @@ -669,13 +666,12 @@ def test_71_antenna_plot(self, field_test):
ffdata.polar_plot_3d_pyvista(
quantity="RealizedGain",
image_path=os.path.join(self.local_scratch.path, "3d2.jpg"),
show=False,
convert_to_db=True,
)
assert os.path.exists(os.path.join(self.local_scratch.path, "3d2.jpg"))

try:
p = ffdata.polar_plot_3d_pyvista(quantity="RealizedGain", show=False, convert_to_db=True)
p = ffdata.polar_plot_3d_pyvista(quantity="RealizedGain", convert_to_db=True)
assert isinstance(p, object)
except Exception:
assert True
Expand All @@ -689,7 +685,6 @@ def test_72_antenna_plot(self, array_test):
title="Contour at {}Hz".format(ffdata.frequency),
image_path=os.path.join(self.local_scratch.path, "contour.jpg"),
convert_to_db=True,
show=False,
)
assert os.path.exists(os.path.join(self.local_scratch.path, "contour.jpg"))

Expand All @@ -699,7 +694,6 @@ def test_72_antenna_plot(self, array_test):
secondary_sweep_value=[-180, -75, 75],
title="Azimuth at {}Hz".format(ffdata.frequency),
image_path=os.path.join(self.local_scratch.path, "2d1.jpg"),
show=False,
)
assert os.path.exists(os.path.join(self.local_scratch.path, "2d1.jpg"))
ffdata.plot_2d_cut(
Expand All @@ -708,7 +702,6 @@ def test_72_antenna_plot(self, array_test):
secondary_sweep_value=30,
title="Azimuth at {}Hz".format(ffdata.frequency),
image_path=os.path.join(self.local_scratch.path, "2d2.jpg"),
show=False,
)

assert os.path.exists(os.path.join(self.local_scratch.path, "2d2.jpg"))
Expand All @@ -721,7 +714,6 @@ def test_72_antenna_plot(self, array_test):
ffdata.polar_plot_3d_pyvista(
quantity="RealizedGain",
image_path=os.path.join(self.local_scratch.path, "3d2.jpg"),
show=False,
convert_to_db=True,
)
assert os.path.exists(os.path.join(self.local_scratch.path, "3d2.jpg"))
Expand All @@ -731,7 +723,6 @@ def test_72_antenna_plot(self, array_test):
title="Contour at {}Hz".format(ffdata1.frequency),
image_path=os.path.join(self.local_scratch.path, "contour1.jpg"),
convert_to_db=True,
show=False,
)
assert os.path.exists(os.path.join(self.local_scratch.path, "contour1.jpg"))

Expand Down
6 changes: 6 additions & 0 deletions _unittest_solvers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

"""
import json
import matplotlib
import os
import shutil
import sys
Expand Down Expand Up @@ -206,3 +207,8 @@ def _method(project_name=None, subfolder=""):
)

return _method

@pytest.fixture(autouse=True)
def matplotlib_use_agg():
"""Configure Matplotlib to use 'Agg' backend for all tests."""
matplotlib.use("Agg")
7 changes: 6 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,17 @@ def setup(app):
# Must be less than or equal to the XVFB window size
pyvista.global_theme["window_size"] = np.array([1024, 768])

# suppress annoying matplotlib bug
# Suppress annoying matplotlib bug
warnings.filterwarnings(
"ignore",
category=UserWarning,
message="Matplotlib is currently using agg, which is a non-GUI backend, so it cannot show the figure.",
)
warnings.filterwarnings(
"ignore",
category=UserWarning,
message="FigureCanvasAgg is non-interactive, and thus cannot be shown",
)

extensions.append("sphinx_gallery.gen_gallery")
sphinx_gallery_conf = {
Expand Down
Loading