File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments