Testing.PlotControl#

Testing.PlotControl.py Utility for controlling matplotlib plots in automated testing. This module was suggested by Copilot to manage plot behavior during tests.

class PlotController#

Bases: object

Controls matplotlib behavior for testing environments.

Environment Variables: - MOLASS_ENABLE_PLOTS: ‘true’ to show plots interactively (default: ‘false’) - MOLASS_SAVE_PLOTS: ‘true’ to save plots to files (default: ‘false’) - MOLASS_PLOT_DIR: directory for saved plots (default: ‘test_plots’) - MOLASS_PLOT_FORMAT: format for saved plots (default: ‘png’)

show_or_save(test_name=None, fig=None)#

Show plot interactively or save to file based on configuration.

Parameters:
  • test_name (str, optional) – Name for the saved plot file

  • fig (matplotlib.figure.Figure, optional) – Figure to save (uses current figure if None)

is_interactive()#

Returns True if plots should be shown interactively.

control_matplotlib_plot(test_func)#

Decorator to control matplotlib behavior for test functions.

Usage: @plot_controller.control_matplotlib_plot def test_my_function():

# Your test code with plots plt.plot([1, 2, 3]) plot_controller.show_or_save(“test_my_function”)

suppress_numerical_warnings(test_func)#

Decorator to suppress numerical computation warnings.

Usage: @plot_controller.suppress_numerical_warnings def test_my_function():

# Your test code that might generate numerical warnings pass

show_or_save(test_name=None, fig=None)#

Convenience function to show or save plot.

is_interactive()#

Returns True if plots should be shown interactively.

control_matplotlib_plot(test_func)#

Decorator for test functions with matplotlib plots.

configure_for_test(test_func)#

Deprecated: Use control_matplotlib_plot instead.

suppress_numerical_warnings(test_func)#

Decorator to suppress numerical computation warnings.