|
5 | 5 | import pytest
|
6 | 6 | from mesa.visualization import SolaraViz
|
7 | 7 |
|
| 8 | + |
8 | 9 | def get_viz_files(directory):
|
9 | 10 | viz_files = []
|
10 | 11 | for root, dirs, files in os.walk(directory):
|
11 | 12 | for file in files:
|
12 |
| - if file in ['app.py', 'viz.py']: |
| 13 | + if file in ["app.py", "viz.py"]: |
13 | 14 | module_name = os.path.relpath(os.path.join(root, file[:-3])).replace(
|
14 | 15 | os.sep, "."
|
15 | 16 | )
|
16 | 17 | viz_files.append(module_name)
|
17 | 18 | return viz_files
|
18 | 19 |
|
| 20 | + |
19 | 21 | @pytest.mark.parametrize("module_name", get_viz_files("examples"))
|
20 | 22 | def test_solara_viz(module_name):
|
21 | 23 | # Add the 'examples' directory to the Python path
|
22 |
| - examples_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'examples')) |
| 24 | + examples_dir = os.path.abspath( |
| 25 | + os.path.join(os.path.dirname(__file__), "..", "examples") |
| 26 | + ) |
23 | 27 | sys.path.insert(0, examples_dir)
|
24 | 28 |
|
25 | 29 | # Add the parent directory of the module to the Python path
|
26 |
| - module_parent_dir = os.path.abspath(os.path.join(examples_dir, os.path.dirname(module_name.replace('.', os.sep)))) |
| 30 | + module_parent_dir = os.path.abspath( |
| 31 | + os.path.join(examples_dir, os.path.dirname(module_name.replace(".", os.sep))) |
| 32 | + ) |
27 | 33 | if module_parent_dir not in sys.path:
|
28 | 34 | sys.path.insert(0, module_parent_dir)
|
29 | 35 |
|
@@ -83,6 +89,7 @@ def test_solara_viz(module_name):
|
83 | 89 | if module_parent_dir in sys.path:
|
84 | 90 | sys.path.remove(module_parent_dir)
|
85 | 91 |
|
| 92 | + |
86 | 93 | # Run the tests
|
87 | 94 | if __name__ == "__main__":
|
88 | 95 | pytest.main([__file__, "-v"])
|
0 commit comments