-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make GIS models testable and test in CI #171
Changes from all commits
8408368
377bf15
805b93d
b662216
533c606
897fe59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Test GIS models | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'gis/**/*.py' # If a gis model is modified | ||
- 'test_gis_examples.py' # If the gis test script is modified | ||
- '.github/workflows/test_gis_examples.yml' # If this workflow is modified | ||
pull_request: | ||
paths: | ||
- 'gis/**/*.py' | ||
- 'test_gis_examples.py' | ||
- '.github/workflows/test_gis_examples.yml' | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 6 * * 1' # Monday at 6:00 UTC | ||
|
||
jobs: | ||
# build-stable: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When will this be enabled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. I think we will want to make a backport to the So then we will make te split of testing pre-releases + git on the main branch, and stable on the Mesa-Geo 0.8.x branch. |
||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - uses: actions/checkout@v4 | ||
# - name: Set up Python | ||
# uses: actions/setup-python@v5 | ||
# with: | ||
# python-version: "3.12" | ||
# - name: Install dependencies | ||
# run: pip install mesa pytest | ||
# - name: Test with pytest | ||
# run: pytest -rA -Werror test_examples.py | ||
|
||
build-pre: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
- name: Install dependencies | ||
run: | | ||
pip install mesa-geo --pre | ||
pip install .[test_gis] | ||
- name: Test with pytest | ||
run: pytest -rA -Werror test_gis_examples.py | ||
|
||
build-main: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
- name: Install dependencies | ||
run: | | ||
pip install -U git+https://github.com/projectmesa/mesa-geo@main#egg=mesa-geo | ||
pip install .[test_gis] | ||
- name: Test with pytest | ||
run: pytest -rA -Werror test_gis_examples.py |
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder to use
uv
later in a separate PR.