Skip to content

Commit 6780059

Browse files
Corvincerht
authored andcommitted
Add testing of all core examples
1 parent dc8989e commit 6780059

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

examples/__init__.py

Whitespace-only changes.

test_examples.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
import os
3+
from mesa import Model
4+
import importlib
5+
6+
7+
def get_models(directory):
8+
models = []
9+
for root, dirs, files in os.walk(directory):
10+
for file in files:
11+
if file == "model.py":
12+
module_name = os.path.relpath(os.path.join(root, file[:-3])).replace(
13+
os.sep, "."
14+
)
15+
16+
module = importlib.import_module(module_name)
17+
for item in dir(module):
18+
obj = getattr(module, item)
19+
if (
20+
isinstance(obj, type)
21+
and issubclass(obj, Model)
22+
and obj is not Model
23+
):
24+
models.append(obj)
25+
26+
return models
27+
28+
29+
@pytest.mark.parametrize("model_class", get_models("examples"))
30+
def test_model_steps(model_class):
31+
model = model_class() # Assume no arguments are needed
32+
for _ in range(10):
33+
model.step()

0 commit comments

Comments
 (0)