Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 3, 2024
1 parent 7894ef9 commit 7b2f764
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@
import pytest
from mesa.visualization import SolaraViz


def get_viz_files(directory):
viz_files = []
for root, dirs, files in os.walk(directory):
for file in files:
if file in ['app.py', 'viz.py']:
if file in ["app.py", "viz.py"]:
module_name = os.path.relpath(os.path.join(root, file[:-3])).replace(
os.sep, "."
)
viz_files.append(module_name)
return viz_files


@pytest.mark.parametrize("module_name", get_viz_files("examples"))
def test_solara_viz(module_name):
# Add the 'examples' directory to the Python path
examples_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'examples'))
examples_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "examples")
)
sys.path.insert(0, examples_dir)

# Add the parent directory of the module to the Python path
module_parent_dir = os.path.abspath(os.path.join(examples_dir, os.path.dirname(module_name.replace('.', os.sep))))
module_parent_dir = os.path.abspath(
os.path.join(examples_dir, os.path.dirname(module_name.replace(".", os.sep)))
)
if module_parent_dir not in sys.path:
sys.path.insert(0, module_parent_dir)

Expand Down Expand Up @@ -83,6 +89,7 @@ def test_solara_viz(module_name):
if module_parent_dir in sys.path:
sys.path.remove(module_parent_dir)


# Run the tests
if __name__ == "__main__":
pytest.main([__file__, "-v"])

0 comments on commit 7b2f764

Please sign in to comment.