File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ import importlib .util
12import json
23from pathlib import Path
34
5+ import matplotlib
46import pytest
57
8+ __examples_dir__ = Path (__file__ ).parent .parent / "docs" / "examples"
9+
610
711@pytest .fixture
812def user_filesystem (tmp_path ):
@@ -17,3 +21,24 @@ def user_filesystem(tmp_path):
1721 json .dump (home_config_data , f )
1822
1923 yield tmp_path
24+
25+
26+ @pytest .fixture (scope = "session" , autouse = True )
27+ def use_headless_matplotlib ():
28+ """Force matplotlib to use a headless backend during tests."""
29+ matplotlib .use ("Agg" )
30+
31+
32+ def load_module_from_path (path : Path ):
33+ """Load a module given an absolute Path."""
34+ spec = importlib .util .spec_from_file_location (path .stem , path )
35+ module = importlib .util .module_from_spec (spec )
36+ spec .loader .exec_module (module )
37+ return module
38+
39+
40+ def run_cmi_script (script_path : Path ):
41+ """General runner for example scripts with a main()."""
42+ module = load_module_from_path (script_path )
43+ assert hasattr (module , "main" ), f"{ script_path } has no main() function"
44+ module .main ()
You can’t perform that action at this time.
0 commit comments