-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: rht <[email protected]>
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import importlib | ||
import os | ||
|
||
import pytest | ||
from mesa import Model | ||
|
||
|
||
def get_models(directory): | ||
models = [] | ||
for root, dirs, files in os.walk(directory): | ||
for file in files: | ||
if file == "model.py": | ||
module_name = os.path.relpath(os.path.join(root, file[:-3])).replace( | ||
os.sep, "." | ||
) | ||
|
||
module = importlib.import_module(module_name) | ||
for item in dir(module): | ||
obj = getattr(module, item) | ||
if ( | ||
isinstance(obj, type) | ||
and issubclass(obj, Model) | ||
and obj is not Model | ||
): | ||
models.append(obj) | ||
|
||
return models | ||
|
||
|
||
@pytest.mark.parametrize("model_class", get_models("gis")) | ||
def test_model_steps(model_class): | ||
model = model_class() # Assume no arguments are needed | ||
for _ in range(10): | ||
model.step() |